• Stars
    star
    197
  • Rank 197,722 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

It is a powerful joystick and touchpad component for UGUI.

UniJoystick

这是一个代码极简但功能相对完善的基于UGUI的摇杆(Joystick)组件。

Summary

  1. 支持设置摇杆半径范围
  2. 支持指示器
  3. 支持配置哪一个轴向使能。
  4. 支持一键将摇杆设置为动态底座摇杆或者静态底座摇杆
  5. 事件驱动,使用UnityEvent 使得事件可以在面板上挂载
  6. 本仓库配备了4个摇杆控制解决方案(Demo,仅供参考):
    • 第一人称 Charactor 控制
    • 第一人称 character 控制,带TouchPad版本
    • 第三人称 Charactor 控制
    • 常规Transform.Translate控制
  7. 适配 Canvas 的 三种 RenderMode。
  8. 鼠标和Touch拖拽前需要检测是否打到 UI 组件,这里有正确姿势

Installation

Install via git URL

You can add https://github.com/Bian-Sh/UniJoystick.git?path=Packages/Joystick to Package Manager

If you want to set a target version, uses the tag so you can specify a version like #2.1.0. For example https://github.com/Bian-Sh/UniJoystick.git?path=Packages/Joystick#1.0.0

  1. Requires a version of unity that supports path query parameter for git packages (Unity >= 2019.3.4f1, Unity >= 2020.1a21).

  2. There is a high chance of failure for users in China.

  3. Package development needs to be done in the Package folder,perhaps for avoid GUID conflicts。

How to use?

  1. Hierarchy 右键选择 “UI/Joystick” 生成摇杆(按需更换 UI 素材)。
  2. 在关注摇杆数据的地方获取摇杆实例并注册 OnValueChanged 事件
  3. 点击运行即可。

示例代码

    public float speed = 5;
    [SerializeField] Joystick joystick;
    void Start()
    {
        joystick.OnValueChanged.AddListener(v =>
        {
            if (v.magnitude != 0)
            {
                transform.Translate(v.x * speed, 0, v.y * speed, Space.World);
                transform.rotation = Quaternion.LookRotation(new Vector3(v.x, 0, v.y));
            }
        });
    }

功能演示

无论静态 or 动态摇杆,都支持 Canvas 的所有 RenderMode

指向器挂载即可使用,不想用销毁即可(有些同学反映指向器用不到,所以剥离并作为可选挂件提供给大家)。

第一人称解决方案示例

第三人称解决方案示例

第一人称解决方案示例 (TouchPad版)

视频中演示了如下内容:

  1. 摇杆驱动人物移动
  2. TouchPad 旋转视角
  3. TouchPad 的灵敏度调节
  4. TouchPad UI 检测,UI上开始的拖拽不触发旋转 ,UI的点击操作不会误触视野旋转功能
  5. TouchPad 测试了响应多个手指的体验,还算正常

友情提醒

如果使用不同的unity导致了控制台各种报错,删除 package.json 即可,路径如下:

结语

因为使用 IpointerXXXHandler 这套事件接口,淡化了 Touch 和 Input API ,所以:

  1. 这个摇杆理论上是支持各种各样的多点触控设备的
  2. 支持同屏多个摇杆实例且互不干扰。
  3. Joystick 支持 Action Input System (示例代码和 touchpad 未做适配) joystick support action input system except example as well as touchpad does not adapt action input system.

ps :在 Microsoft's Surface Pro 、小米Pad 9 测试OK。

My Blog

[Unity 3d] 使用UGUI做一个类似王者荣耀的摇杆 - 简书

More Repositories

1

Assemblies-Hotfix-Toolkit-Unity

Assemblies hotfix with unity addressable , for windows and android , both mono and IL2CPP scripting backend,IL2CPP hotfix powered by wolong(HybridCLR)
C#
173
star
2

Security-Camera-Toolkit-For-Unity

一个在 Unity 中播放国内头部监控厂商实时监控的框架 A toolkit for playing security camera in unity
C#
58
star
3

Unity-MecanimEventSystem

This is a chain programming style callback System for Animator of Unity
C#
48
star
4

ET-Network-Module

从 ET6.0 中精简出来的网络模块(TCP ),可以与 ET Server 通信。
C#
45
star
5

Unity-async-await-tcp

This is an async/await tcp communication (client and server inside) in unity.simple yet powerful!
C#
44
star
6

Script-Encoding-Converter

unity 编辑器扩展,可以检测代码编码并自动转码到 UTF8 丧心病狂的好用,你值得拥有.Editor extension for converting script encoding from gb2312 to utf8 that you must have.
C#
32
star
7

RTSP-Player-For-Unity-WebGL

测试网页居中弹窗播放 RTSP 视频,可用于接 rtsp 监控,同时演示怎么接入到 webgl 上
JavaScript
23
star
8

Timer-For-Unity

这是一个很酷的链式编程风格的定时器,而且它还支持在非主线程中使用并正常的使用Unity组件,为Unity更好的多线程编程体验带来一点点暖意
C#
23
star
9

UniCoroutineManager

Coroutine Manager For Unity 3d
C#
20
star
10

UniEventSystem

This is a generic Event-Bus for Unity
C#
19
star
11

Dotween-Animation-Provider

Dotween Extension for better preview experience
C#
14
star
12

Unity-Application-Auto-Builder

Unity 一键打包工具,适用于 频繁切换打包场景的情景,一劳永逸,一键打多个app
C#
13
star
13

FileSystem4UnityStandaloneApp

File system For “exe” SoftWare those made with Unity.
C#
9
star
14

UniFileOpenDialog

FileOpenDialog/ FileSaveDialog For Unity . With Topmost Function.
C#
9
star
15

ScriptableObject-Asset-Creator

通用的 ScriptableObject .asset 文件生成工具/Generic ScriptableObject ".asset" file generation tool.
C#
8
star
16

System-Tray-Icon-For-Unity

为 Unity 打包的Standalone App 提供 system tray
C#
7
star
17

SmartRectTransformSizeHandler

Smart RectTransform size and Pose handler with Anchors Max/Min considered
C#
6
star
18

Simple-Customize-ERP-System

this is a pretty simple customized erp system ,very niche.
C#
5
star
19

JsonUsingInUnity

C#
5
star
20

Enemy-Position-Indicator

敌人位置指示器
C#
4
star
21

Addressabls-Test

测试基于 Addressabls 的资源增量更新与资源版本管理
ShaderLab
4
star
22

UniMP3RuntimeLoader

With this Repo. you can use WWW as well as UnityWebRequest to download MP3 and play it at runtime/unityeditor .
C#
4
star
23

No-Component-File-Uploader-For-Unity

This is a no component file uploader (pure asp uploader) for unity
C#
3
star
24

Unity-Editor-Coroutine

Edtor Coroutine For Unity
C#
3
star
25

UniVRMViewer

This is a vrm viewer unity project.
C#
3
star
26

MiniMap-For-Unity-UGUI

Simple Interactive MiniMap for Unity UGUI
C#
3
star
27

unity-drones-multiplayer-tinyrpc

这是一个为 TinyRPC 准备的简易多人游戏示例,仅仅演示了简单的位置同步!This is a simple multiplayer game example prepared for TinyRPC, only demonstrating basic pose synchronization!
C#
3
star
28

UGUI-Hover-Light-Effect

使用 UGUI + Shader 做一个 Windows10 日历悬浮高亮效果 Create a Windows 10 calendar floating highlight effect using UGUI + Shader.
ShaderLab
2
star
29

Verification-Code-Generator

This is a repo for generating a simple verification code in unity made application (windows only)
C#
1
star
30

DragFile4unityRT

C#
1
star
31

SQLite-Test

SQLite - Net 的测试项目
C#
1
star
32

MeshBoundViewer

一个简单网格包围盒查看器,a mesh bound viewer for simple meshs.
C#
1
star
33

CsvUtility-For-Unity

This tool is a compact single file co-created by me and AI for CSV read/write. It is user-friendly, customizable, and supports bilingual usage.此工具是我与 AI 共同打造的小巧单文件,可用于 CSV 读写。本工具易于使用,支持自定义。
C#
1
star
34

MiraikomachiUnity

这是一个 Windows 10 多点触控的 Demo,测试了简单的单指拖拽相机旋转,双指挤压缩放视野,当然,亮点就是里面跳舞的小姐姐啦,超有爱!(Unity2018.2.16f1)
C#
1
star
35

TinyWebServer

Simple WebServer for hosting WebGL in editor,为编辑下托管 webgl 应用而生
C#
1
star