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;

        }
    }
}

 

posted @ 2019-10-28 20:10  D个人笔记  阅读(1559)  评论(0编辑  收藏  举报