HTC Vive開發筆記之手柄控制


怎么安裝設備,配置環境我就不說了,自行百度,教程很多也很簡單。接下來說下Vive手柄的控制。

手柄是HTC Vive的重要交互手段,我們通過第一個圖片應該對其有一個直觀的了解了,總共是九個按鈕:

    • 第一個是菜單按鈕;
    • 2,3,4,5分別對應的是Trackpad/Touchpad的上下左右,有時候對應的是XBox手柄的▲OX四個按鈕或者搖桿;
    • 6對應的是系統按鈕/Steam;
    • 7是Trigger/扳機,對應大多數FPS游戲里面的槍械的Shoot/Fire;
    • 8對應的Grip/緊握在手柄的左右兩側各有一個,有時候我們用它來翻頁;
    • 9其實是Trackpad/Touchpad在Z軸的一個延伸,相當於是點擊事件Click. 

 

using UnityEngine;
using System.Collections;
/// <summary>
/// 扳機控制觸發事件
/// </summary>
public class ComfirmController : MonoBehaviour {
    //手柄
    SteamVR_TrackedObject trackedObj;
 
    void Awake()
    {
        //獲取手柄腳本組件
        trackedObj = GetComponent<SteamVR_TrackedObject> ();
    }
 
    // Use this for initialization
    void Start () {
     
    }
     
    // Update is called once per frame
    void FixedUpdate () {
         
        //獲取手柄輸入
        var device = SteamVR_Controller.Input ((int)trackedObj.index);
 
        //此處可以換其他的函數觸發GetPress/GetTouch /GetPressUp GetTouchDown/GetTouchUp/GetAxis
        if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))  
        {  
            Debug.Log("按下圓盤");  
        }  
        else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))  
        {  
          
            Debug.Log("按下扳機鍵");  
        }  
        else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))  
        {  
          
            Debug.Log("按下手柄側鍵");  
        }  
        else if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))  
        {  
          
            Debug.Log("按下手柄菜單鍵");  
        }  
        else if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))  
        {  
  
            Debug.Log("按下手柄菜單鍵");  
        }  
 
    }
}

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM