Skip to content

Instantly share code, notes, and snippets.

@mmaletin
Created April 11, 2019 13:38
Show Gist options
  • Save mmaletin/7072151c7d8e6ffe0e2b7423716da76e to your computer and use it in GitHub Desktop.
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.
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