码迷,mamicode.com
首页 > 编程语言 > 详细

Unity HTCVR 设备手柄控制

时间:2019-10-28 21:09:38      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:san   active   object   this   date()   void   down   get   span   

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;

        }
    }
}

 

Unity HTCVR 设备手柄控制

标签:san   active   object   this   date()   void   down   get   span   

原文地址:https://www.cnblogs.com/DGJS/p/11755221.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!