项目场景:VR实时跳转场景
提示:这里简述项目相关背景:
使用VRTK插件和SteamVR
Unity2019.4.18
问题描述
提示:这里描述项目中遇到的问题:
在使用VRTK时跳转场景UI交互会消失,手柄功能会丢失。
原因分析:
这个叫EventSystem的东西会自动隐藏,所以UI交互功能全部丢失
解决方案:
新建空物体挂载脚本EventHelper(注:此脚本非VRTK脚本)
public GameObject EventSystem;
public VRTK_UIPointer PointerController;
public VRTK_UIPointer PointerController2;
private VRTK_VRInputModule[] inputModule;
private void Start()
{
StartCoroutine(LateStart(1));
}
private void Update()
{
if (inputModule != null)
{
if (inputModule.Length > 0)
{
inputModule[0].enabled = true;
if (inputModule[0].pointers.Count == 0)
inputModule[0].pointers.Add(PointerController);
if (inputModule.Length > 0)
{
inputModule[0].enabled = true;
if (inputModule[0].pointers.Count == 1)
inputModule[0].pointers.Add(PointerController2);
}
}
else
inputModule = EventSystem.GetComponents<VRTK_VRInputModule>();
}
}
IEnumerator LateStart(float waitTime)
{
yield return new WaitForSeconds(waitTime);
EventSystem.SetActive(true);
EventSystem.GetComponent<EventSystem>().enabled = false;
inputModule = EventSystem.GetComponents<VRTK_VRInputModule>();
}
是的就是这么简单
最后在挂载我们场景中的EventSystem和我们的连个手柄就可以了