Created
April 11, 2019 13:38
-
-
Save mmaletin/7072151c7d8e6ffe0e2b7423716da76e to your computer and use it in GitHub Desktop.
This script stops new VR poses from being applied when Unity editor is paused. It fixes frame debugger. Add it to camera and controllers, and any other tracked objects.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
#if UNITY_EDITOR | |
using Valve.VR; | |
using UnityEditor; | |
#endif | |
// This script stops new VR poses from being applied when Unity editor is paused. | |
// It fixes frame debugger. Add it to camera and controllers, and any other tracked objects. | |
public class VRFrameDebuggerFix : MonoBehaviour | |
{ | |
#if UNITY_EDITOR | |
private Vector3 position; | |
private Quaternion rotation; | |
private void Start() | |
{ | |
EditorApplication.pauseStateChanged += OnPauseStateChanged; | |
SteamVR_Events.NewPosesApplied.Listen(OnNewPosesApplied); | |
} | |
private void OnNewPosesApplied() | |
{ | |
if (EditorApplication.isPaused) | |
{ | |
transform.SetPositionAndRotation(position, rotation); | |
} | |
} | |
private void OnPauseStateChanged(PauseState pauseState) | |
{ | |
if (pauseState == PauseState.Paused) | |
{ | |
position = transform.position; | |
rotation = transform.rotation; | |
} | |
} | |
private void OnDestroy() | |
{ | |
EditorApplication.pauseStateChanged -= OnPauseStateChanged; | |
SteamVR_Events.NewPosesApplied.RemoveListener(OnNewPosesApplied); | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment