HTC VIVE丨6. VR中的UI互動
阿新 • • 發佈:2019-01-08
VR中UI一般構建步驟
1、新建Canvas,放在其依附物體下
2、Render Mode改為World Space
3、修改縮放,建議值0.001
4、修改解析度Dynamic Pixel Per Unit,建議值3
5、新增相關元素
InteractionSystem中的UI互動
a、按鈕點選基於Collider,一般放置BoxCollider
b、UIElement類:在InteractionSystem中實現UI的互動,必須掛載此指令碼以標記可互動的UI
c、按鈕一般事件為OnHandClick,手柄點選Trigger鍵啟用
d、ControllerButtonHints類:呼叫一系列靜態方法以實現按鈕高亮、文字提示
Demo
構建互動按鈕,實現手柄文字提示以及按鈕高亮
1、建立UI,為其新增UIElement
On Hand Click:當手柄點選UI時(不必按動手柄上的按鍵),觸發事件
2、在UI輪廓新增BoxCollider,使其包裹住UI
3、新建承載觸發事件指令碼的gameObject,賦值到On Hand Click()
程式碼示例:
using UnityEngine; using Valve.VR.InteractionSystem; public class gameObjectManager : MonoBehaviour { public void ShowHints(Hand hand) { //高亮顯示手柄按鈕 ControllerButtonHints.ShowButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_Grip); ControllerButtonHints.ShowButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad); ControllerButtonHints.ShowButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_ApplicationMenu); //顯示文字資訊 ControllerButtonHints.ShowTextHint(hand, Valve.VR.EVRButtonId.k_EButton_Grip,"換彈夾"); } public void HideHints(Hand hand) { //單個隱藏手柄高亮按鍵 ControllerButtonHints.HideButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_Grip); //全部隱藏 ControllerButtonHints.HideAllButtonHints(hand); ControllerButtonHints.HideTextHint(hand, Valve.VR.EVRButtonId.k_EButton_Grip); ControllerButtonHints.HideAllTextHints(hand); } }
4、調整手柄互動時輪廓顏色,可通過下圖所示實現