原因可能是因為StreamVR軟件更新與Unity的插件接口不匹配,
1.可能是SteamVR版本過高/低 或Unity版本過低/高
2.可以將如下代碼替換
3.將SteamVR_UpdatePoses 腳本掛到VR相機上(也就是eyes上)
using UnityEngine;
using Valve.VR;
[RequireComponent(typeof(Camera))]
public class SteamVR_UpdatePoses : MonoBehaviour
{
void Awake()
{
var camera = GetComponent<Camera>();
#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版本中 有可能出現手柄顯示但是位置不匹配的問題. 可以通過代碼在運行游戲時修改相機的Field of View 這個值是不被允許修改的. 只要通過代碼修改一下, 手柄位置即可匹配
4, 標題2的代碼如果不好使再試試下邊這個
using UnityEngine;
using Valve.VR;
[RequireComponent(typeof(Camera))]
public class SteamVR_UpdatePoses : MonoBehaviour
{
#if !(UNITY_5_6)
void Awake()
{
var camera = GetComponent<Camera>();
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();
}
}
}
最后還有一個問題. 是關於VRTK的,我還遇到過手柄顯示,但是某些按鍵(如扳機,抓取,touch盤,菜單,一共就這四個)不能用 , 這也是因為SteamVR更新了. 相信 遇到過這個問題的都是打開了Steam,然后Steam自動將SteamVR更新了. 之后Unity中如果使用VRTK就有可能出現這個問題.
解決辦法:
找到手柄VRTK_ControllerEvent腳本, 將里邊的Touch觸發的地方都修改為Press觸發即可;