微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Unity InputSystem

最近迁移项目到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());//鼠标所在的当前位置
        }
    }


}

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐