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触发即可;
本博客所有内容均为原创,转载请注明出处.