如何在 VR/Cardboard unity 中垂直居中
How to recenter vertically in GVR / Cardboard unity
通话中
GvrViewer.Instance.Recenter ();`
仅水平居中视图,我也需要它垂直。
我使用的是最新的 unity beta 和 GVR 0.8`
您可以通过让您的 VR 相机对象成为另一个对象(我们称之为父对象)的子对象并沿与 VR 相机旋转相反的方向旋转父对象来重新居中。这个简单的脚本可以做到(附加到父级):
public class Recenterer:MonoBehaviour
{
public Transform VRcam; // drag the child VR cam here in the inspector
public void Recenter()
{
transform.localRotation = Quaternion.Inverse(VRcam.rotation);
}
}
从 Google VR SDK 1.50(和 Unity 5.6)开始,您可以做到
transform.eulerAngles = new Vector3(newRot.x, newRot.y, newRot.z);
UnityEngine.VR.InputTracking.Recenter();
此外,如果您不想混淆,您还需要捕获 GvrEditorEmulator 实例并将其重新定位。
#if UNITY_EDITOR
gvrEditorEmulator.Recenter();
#endif
重新居中 GvrEditorEmulator 虽然目前似乎效果不佳,但如果您禁用它,您将看到主相机的重新居中工作。
通话中
GvrViewer.Instance.Recenter ();`
仅水平居中视图,我也需要它垂直。
我使用的是最新的 unity beta 和 GVR 0.8`
您可以通过让您的 VR 相机对象成为另一个对象(我们称之为父对象)的子对象并沿与 VR 相机旋转相反的方向旋转父对象来重新居中。这个简单的脚本可以做到(附加到父级):
public class Recenterer:MonoBehaviour
{
public Transform VRcam; // drag the child VR cam here in the inspector
public void Recenter()
{
transform.localRotation = Quaternion.Inverse(VRcam.rotation);
}
}
从 Google VR SDK 1.50(和 Unity 5.6)开始,您可以做到
transform.eulerAngles = new Vector3(newRot.x, newRot.y, newRot.z);
UnityEngine.VR.InputTracking.Recenter();
此外,如果您不想混淆,您还需要捕获 GvrEditorEmulator 实例并将其重新定位。
#if UNITY_EDITOR
gvrEditorEmulator.Recenter();
#endif
重新居中 GvrEditorEmulator 虽然目前似乎效果不佳,但如果您禁用它,您将看到主相机的重新居中工作。