Unity HTCVR 設備手柄控制


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HTC.UnityPlugin.Vive;
using UnityEngine.SceneManagement;

public class HandFunction : MonoBehaviour
{
    public static HandFunction hand_function;

    public GameObject RightRay;
    public bool Ray_bool;    //射線開關

    public bool Ray_Canvas;  //ui開關
    private void Awake()
    {
        hand_function = this;
    }

    void Start()
    {
        RightRay.SetActive(false);
        Ray_Canvas = false;
    }

    void Update()
    {

        PressMenuKey();
        PressTriggerKey();
        PressGripKey();
    }


    /// <summary>
    /// 按下應用鍵
    /// </summary>
    void PressMenuKey()
    {
        if (ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Menu)/*|| ViveInput.GetPressDown(HandRole.LeftHand, ControllerButton.Menu)*/)
        {
            Ray_bool = !Ray_bool;
            RightRay.SetActive(Ray_bool);
        }
        if (ViveInput.GetPressDown(HandRole.LeftHand,ControllerButton.Menu))
        {
            if (SceneVR.scene_vr.UiOpen==true)
            {
                Ray_Canvas = !Ray_Canvas;
                SceneVR.scene_vr.UICanvasVR.SetActive(Ray_Canvas);
            }
        }
    }

    /// <summary>
    /// 按下扳機鍵
    /// </summary>
    void PressTriggerKey()
    {
        if (ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Trigger)|| ViveInput.GetPressDown(HandRole.LeftHand, ControllerButton.Trigger))
        {
            SceneVR.scene_vr.IsRayOpenToolVR = true;

        }
        if (ViveInput.GetPressUp(HandRole.RightHand, ControllerButton.Trigger)|| ViveInput.GetPressUp(HandRole.LeftHand, ControllerButton.Trigger))
        {
            SceneVR.scene_vr.IsRayOpenToolVR = false;
        }
    }

    /// <summary>
    /// 按下圓盤鍵
    /// </summary>
    void PressPadKey()
    {
        if (ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Pad))
        {

        }
    }

    /// <summary>
    /// 按下側握鍵
    /// </summary>
    void PressGripKey()
    {
        if (ViveInput.GetPressDown(HandRole.LeftHand,ControllerButton.Grip))
        {
            SceneVR.scene_vr.Rerouting();
            SceneVR.scene_vr.IsaniOpen();
            SceneVR.scene_vr.IsAniOpen = false;

        }
    }
}

 


免責聲明!

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



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