VR中UI的出现场景
- 菜单
- 游戏元素UI,如血条、生命值、剩余时间
- 对话框
- 提示信息
- 十字光标
VR中的UI一般构建步骤
- 新建Canvas
- Render Model改为World Space
- 修改缩放
- 修改Dynamic Pixel Per Unit
- 添加相关元素
Interaction System 中的UI交互
- 按钮点击基于Collider,一般放置为BoxCollider;
- UIElement类:在Interaction system中实现UI的交互,必须挂载此脚本已标记可交互的UI;
- 按钮一般事件为OnHandClick,手柄点击Trigger键激活;
- ControllerButtonHints类,调用一系列静态方法实现按钮高亮和文字提示。
示例:构建交互按钮,实现手柄文字提示和按钮高亮
![这里写图片描述](https://img-blog.csdn.net/20180722142454405?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW9rdW56aGFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR.InteractionSystem;
public class GameManager : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void ShowHits(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,"画线");
ControllerButtonHints.ShowTextHint(hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad, "选择颜色");
}
public void HideHits(Hand hand)
{
ControllerButtonHints.HideButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_Grip);
ControllerButtonHints.HideButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad);
ControllerButtonHints.HideButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_ApplicationMenu);
ControllerButtonHints.HideAllTextHints(hand);
}
}