美文网首页
VR手柄事件

VR手柄事件

作者: 吐泡泡的小鲤鱼 | 来源:发表于2017-06-15 11:55 被阅读0次

---------------我相信时间真的能改变一个人,就像你以前很丑,后来越来越丑。-----------------------------------


自己总结的手柄的一些按钮事件基于HTC VIVE设备,unity引擎

直接代码吧,我的注释很清楚

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class MyTranningScripts : MonoBehaviour { 

  //手柄 

  SteamVR_TrackedObject trackedObj;

// Use this for initialization

void Awake () {  

    trackedObj = GetComponent();

}

// Update is called once per frame

void FixedUpdate () {

//获取手柄输入

var device = SteamVR_Controller.Input((int)trackedObj.index);

//此处可以换其他的函数触发GetPress/GetTouch /GetPressUp GetTouchDown/GetTouchUp/GetAxis

#region    圆盘事件

//if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))

//{

//    print("刚触摸圆盘");

//}

//if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))

//{

//    print("正在触摸圆盘");

//}

//if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad))

//{

//    print("抬起圆盘");

//}

//if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))

//{

//    print("按下圆盘");

//}

//if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))

//{

//    print("正在按着圆盘");

//}

//if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))

//{

//    print("松开圆盘");

//}

#endregion

#region    扳机事件

//if (device.GetPressDown (SteamVR_Controller.ButtonMask .Trigger))

//{

//    Debug.Log("我按下了扳机键/Trigger");

//}

//if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))

//{

//    Debug.Log("我正在按着扳机键/Trigger");

//}

//if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))

//{

//    Debug.Log("我松开了扳机键/Trigger");

//}

#endregion

#region  手柄侧键事件(暂时不会区分左右侧键)

if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip ))

{

Debug.Log("我按下了手柄侧键/Grip");

}

if (device.GetPress(SteamVR_Controller.ButtonMask.Grip))

{

Debug.Log("我正在按着手柄侧键/Grip");

}

if (device.GetPressUp(SteamVR_Controller.ButtonMask.Grip))

{

Debug.Log("我松开了手柄侧键/Grip");

}

#endregion

#region    手柄菜单键事件

//if (device.GetPressDown (SteamVR_Controller.ButtonMask .ApplicationMenu))

//{

//    Debug.Log("按下手柄菜单键/ApplicationMenu");

//}

#endregion

}

}

相关文章

网友评论

      本文标题:VR手柄事件

      本文链接:https://www.haomeiwen.com/subject/xobyqxtx.html