zoukankan      html  css  js  c++  java
  • 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());//鼠标所在的当前位置
            }
        }
    
    
    }
  • 相关阅读:
    C#-项目属性设置
    SQL--连接字符串总结
    希尔排序实现(不太满意)
    选择排序实现
    用位运算实现 | 与 ^ 的功能
    如何初始化一个定长List<T>
    线程池与Threadlocal
    常用类
    基本数据类型介绍
    eclipse快捷键
  • 原文地址:https://www.cnblogs.com/Mr-Prince/p/14639686.html
Copyright © 2011-2022 走看看