Interaction System入门之手柄按钮高亮及文字提示

来源:互联网 发布:网络教育如何报名 编辑:程序博客网 时间:2024/05/16 02:03

按钮点击基于Collider,一般放置BoxCollider

UIElement类:在InteractionSystem中实现UI的交互,必须挂载此脚本以标记为可交互的UI

按钮一般事件为OnHandClick,手柄点击Trigger键激活

ControllerButtonHints类:调用一系列静态方法实现按钮高亮、文字提示


一、删除Main Camera,创建Plane,并设置大小和位置



2、将player拖进场景,并设置大小和位置


3、创建canvas并进行设置


4、在Canvase下新建两个子物体Button,设置大小、位置并添加UI Element组件


4、创建一个脚本GameManager

using System.Collections;using System.Collections.Generic;using UnityEngine;using Valve.VR.InteractionSystem;public class GameManager : MonoBehaviour {void Start () {        Debug.Log("show Start.......................");    }void Update () {        Debug.Log("show Update.......................");    }    //显示提示    public void showHints(Hand hand)    {        Debug.Log("show hints.......................");        //高亮Touch Pad键        ControllerButtonHints.ShowButtonHint(hand,Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad);        //高亮Grip键        ControllerButtonHints.ShowButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_Grip);        //高亮Menu键        ControllerButtonHints.ShowButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_ApplicationMenu);        //Touch Pad键显示瞬移        ControllerButtonHints.ShowTextHint(hand,Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad, "瞬移");        //Trigger键显示换弹夹        ControllerButtonHints.ShowTextHint(hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger, "换弹夹");    }    //隐藏提示    public void hideHints(Hand hand)    {        Debug.Log("hide hints.......................");        //隐藏Touch Pad键        ControllerButtonHints.HideButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad);        //隐藏Grip键        ControllerButtonHints.HideButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_Grip);        //隐藏Menu键        ControllerButtonHints.HideButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_ApplicationMenu);        //隐藏字体        ControllerButtonHints.HideAllTextHints(hand);    }}

5、创建一个空物体,并添加该脚本



6、选中button,点击“+”号,将GameObject拖动到如图的位置



7、在No Function的位置选中GameManager-->showHints(刚才定义的方法),同样的方式设置给另一个按钮



8、运行后点击显示按钮,按钮高亮并在相应按钮位置显示文字


9、运行后点击关闭按钮,高亮按钮消失,文字消失











注:参考资料:

http://edu.manew.com/course/344/learn#lesson/5605


阅读全文
0 0