Unity InputSystem

2021-06-04 21:04

阅读:550

标签:vat   中间   point   key   ESS   cti   engine   bsp   鼠标右键   

最近迁移项目到UnityXR框架,发现UnityXR框架使用了新的输入系统(InputSystem)然后就学习了一下。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;


public class PlayerInputSys : MonoBehaviour
{
    Keyboard m_Keyboard = Keyboard.current;
    Mouse m_Mouse = Mouse.current;
    Pointer m_Pointer = Pointer.current;

    private void Update()
    {
        if(m_Keyboard !=null)
        {
            if (m_Keyboard.wKey.wasPressedThisFrame)
            {
                Debug.Log("按下了W键");
            }
            if (m_Keyboard.wKey.wasReleasedThisFrame)
            {
                Debug.Log("释放了W键");
            }

            Debug.Log("是否按住W键:" +m_Keyboard.wKey.IsPressed());
        }
        if(m_Mouse != null)
        {
            Debug.Log(m_Mouse.scroll.ReadValue());
            if(m_Mouse.leftButton.wasPressedThisFrame)
            {
                Debug.Log("按下了鼠标左键");
            }
            if(m_Mouse.rightButton.wasPressedThisFrame)
            {
                Debug.Log("按下了鼠标右键");
            }
            if (m_Mouse.middleButton.wasPressedThisFrame)
            {
                Debug.Log("按下了鼠标中间");
            }
        }
        if(m_Pointer !=null)
        {
            Debug.Log(m_Pointer.delta.ReadValue());//与上一帧的偏移量
            Debug.Log(m_Pointer.position.ReadValue());//鼠标所在的当前位置
        }
    }


}

 

Unity InputSystem

标签:vat   中间   point   key   ESS   cti   engine   bsp   鼠标右键   

原文地址:https://www.cnblogs.com/Mr-Prince/p/14639686.html

上一篇:Javascript深拷贝

下一篇:排序链表


评论


亲,登录后才可以留言!