基于Unity 關(guān)于SteamVR中 手柄/Tracker不顯示的問(wèn)題
原因可能是因?yàn)镾treamVR軟件更新與Unity的插件接口不匹配,
1.可能是SteamVR版本過(guò)高/低 ?或Unity版本過(guò)低/高
2.可以將如下代碼替換
3.將SteamVR_UpdatePoses 腳本掛到VR相機(jī)上(也就是eyes上)
using UnityEngine;
using Valve.VR;
[RequireComponent(typeof(Camera))]
public class SteamVR_UpdatePoses : MonoBehaviour
{
void Awake()
{
var camera = GetComponent();
#if !(UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0)
camera.stereoTargetEye = StereoTargetEyeMask.None;
#endif
camera.clearFlags = CameraClearFlags.Nothing;
camera.useOcclusionCulling = false;
camera.cullingMask = 0;
camera.depth = -9999;
}
void OnPreCull()
{
var compositor = OpenVR.Compositor;
if (compositor != null)
{
var render = SteamVR_Render.instance;
compositor.GetLastPoses(render.poses, render.gamePoses);
SteamVR_Utils.Event.Send("new_poses", render.poses);
SteamVR_Utils.Event.Send("new_poses_applied");
}
}
}
3.在unity2017版本中 ?有可能出現(xiàn)手柄顯示但是位置不匹配的問(wèn)題. 可以通過(guò)代碼在運(yùn)行游戲時(shí)修改相機(jī)的Field of View 這個(gè)值是不被允許修改的. 只要通過(guò)代碼修改一下, 手柄位置即可匹配
4, ?標(biāo)題2的代碼如果不好使再試試下邊這個(gè)
using UnityEngine;
using Valve.VR;
[RequireComponent(typeof(Camera))]
public class SteamVR_UpdatePoses : MonoBehaviour
{
#if !(UNITY_5_6)
void Awake()
{
var camera = GetComponent();
camera.stereoTargetEye = StereoTargetEyeMask.None;
camera.clearFlags = CameraClearFlags.Nothing;
camera.useOcclusionCulling = false;
camera.cullingMask = 0;
camera.depth = -9999;
}
#endif
void OnPreCull()
{
var compositor = OpenVR.Compositor;
if (compositor != null)
{
var render = SteamVR_Render.instance;
compositor.GetLastPoses(render.poses, render.gamePoses);
SteamVR_Events.NewPoses.Send(render.poses);
SteamVR_Events.NewPosesApplied.Send();
}
}
}
最后還有一個(gè)問(wèn)題. 是關(guān)于VRTK的,我還遇到過(guò)手柄顯示,但是某些按鍵(如扳機(jī),抓取,touch盤,菜單,一共就這四個(gè))不能用 , 這也是因?yàn)镾teamVR更新了. 相信 遇到過(guò)這個(gè)問(wèn)題的都是打開(kāi)了Steam,然后Steam自動(dòng)將SteamVR更新了. 之后Unity中如果使用VRTK就有可能出現(xiàn)這個(gè)問(wèn)題.
解決辦法:
找到手柄VRTK_ControllerEvent腳本, 將里邊的Touch觸發(fā)的地方都修改為Press觸發(fā)即可;