public void OnMouseDown(InputAction.CallbackContext context) { if (context.phase == InputActionPhase.Performed) {//方法1 //Set up the new Pointer Event PointerEventData m_PointerEventData = new PointerEventData(m_EventSystem); //Set the Pointer Event Position to that of the mouse position m_...
3. Unity的Project中右键->Create->Input Actions。 4. Action Maps取名,如Player。Actions右边小“+”添加New action,取名如:Action_Move,表示鼠标移动。此时对应Properties->Action->Action Type: Pass Through; Control Type: Vector 2. 继续添加Binding:Mouse->Positions. 5. 设置鼠标触发事件。New action:Actio...
InputAction move = new InputAction(binding: "<Mouse>/Position"); move.performed += OnMoveAction; move.Enable(); } 例6: InputAction click = new InputAction(binding: "<Mouse>/leftButton"); click.performed += ctx => { RaycastHit hit; Vector3 coor = Mouse.current.position.ReadValue(); ...
inputAction.Enable(); inputAction.Gameplay.MouseDown.performed+=ctx=> { Debug.Log("按下:"+UnityEngine.InputSystem.Mouse.current.position.ReadValue()); }; inputAction.Gameplay.MouseDrag.performed+=ctx=> { Debug.Log("拖拽:"+UnityEngine.InputSystem.Mouse.current.position.ReadValue()); }; inputA...
voidInputTest(){GameInput inputAction=newGameInput();//GameInput为场景中的InputSystem控制器inputAction.Enable();inputAction.Gameplay.MouseDown.performed+=ctx=>{Debug.Log("按下:"+UnityEngine.InputSystem.Mouse.current.position.ReadValue());};inputAction.Gameplay.MouseDrag.performed+=ctx=>{Debug.Log(...
直接使用InputSystem的方法很简单,系统提供了各种设备对应的管理类和当前实例 Gamepadgamepad=GamePad.current;// 手柄Joystickjoystick=Joystick.current;// 摇杆Keyboardkeyboard=Keyboard.current;// 键盘Pointerpointer=Pointer.current;// 指针,屏幕上的指定位置操作,包括鼠标,触屏以及手写笔等子类Mousemouse=Mouse.current...
直接使用InputSystem的方法很简单,系统提供了各种设备对应的管理类和当前实例 Gamepadgamepad=GamePad.current;// 手柄Joystickjoystick=Joystick.current;// 摇杆Keyboardkeyboard=Keyboard.current;// 键盘Pointerpointer=Pointer.current;// 指针,屏幕上的指定位置操作,包括鼠标,触屏以及手写笔等子类Mousemouse=Mouse.current...
InputSystem起作用的设置 我们选用“Input System Package(New)”或者“Both”都可以。 Input System的使用方式大致分为两种,一种是通过InputSysten Package提供的组件,在编辑器通过拖拽,选择,挂载等方式,进行函数与输入动作的绑定;另一种是使用代码对函数与输入动作进行绑定。
在Edit->Project Settings->Player->Active Input Handling中,可以选择激活InputSystem还是Input类还是二者都使用。如果比较绝对的话可以只使用New来杜绝旧端遗留。 使用 如果想和传统Input类差不多的写法,也没有什么难度,代码如下: readonlyGamepadgamepad=Gamepad.current;//手柄readonlyKeyboardkeyboard=Keyboard.current...
直接使用InputSystem的方法很简单,系统提供了各种设备对应的管理类和当前实例 Gamepad gamepad = GamePad.current;//手柄Joystick joystick = Joystick.current;//摇杆Keyboard keyboard = Keyboard.current;//键盘Pointer pointer = Pointer.current;//指针,屏幕上的指定位置操作,包括鼠标,触屏以及手写笔等子类Mouse mouse...