diff --git a/com.unity.cinemachine/Runtime/Behaviours/CinemachineBrain.cs b/com.unity.cinemachine/Runtime/Behaviours/CinemachineBrain.cs index f4a80b576..22a9a92b1 100644 --- a/com.unity.cinemachine/Runtime/Behaviours/CinemachineBrain.cs +++ b/com.unity.cinemachine/Runtime/Behaviours/CinemachineBrain.cs @@ -164,7 +164,6 @@ public LensModeOverrideSettings LensModeOverride #if CINEMACHINE_UIELEMENTS && UNITY_EDITOR DebugText m_DebugText; - CinemachineDebugDisplay m_DebugDisplay; #endif void OnValidate() @@ -224,8 +223,6 @@ void OnDisable() CinemachineDebug.OnGUIHandlers -= OnGuiHandler; m_DebugText?.Dispose(); m_DebugText = null; - if (m_DebugDisplay != null) - m_DebugDisplay.enabled = false; #endif s_ActiveBrains.Remove(this); @@ -247,33 +244,6 @@ void OnSceneUnloaded(Scene scene) ManualUpdate(); } -#if UNITY_EDITOR && CINEMACHINE_UIELEMENTS - void Update() - { - if (ShowDebugText || CinemachineDebug.GameViewGuidesEnabled) - { - // Make sure we have a CinemachineDebugDisplay component - if (m_DebugDisplay == null && !TryGetComponent(out m_DebugDisplay)) - { - m_DebugDisplay = gameObject.AddComponent(); - m_DebugDisplay.hideFlags = HideFlags.DontSave | HideFlags.HideInInspector; - } - m_DebugDisplay.enabled = true; - } - else if (m_DebugDisplay != null) - { - // Get rid of the CinemachineDebugDisplay component, so no OnGUI calls are made - RuntimeUtility.DestroyObject(m_DebugDisplay); - m_DebugDisplay = null; - } - if (!ShowDebugText && m_DebugText != null) - { - m_DebugText.Dispose(); - m_DebugText = null; - } - } -#endif - void LateUpdate() { if (UpdateMethod != UpdateMethods.ManualUpdate) @@ -307,8 +277,24 @@ void OnPreCull() } #if CINEMACHINE_UIELEMENTS + + void OnGUI() + { + if ((ShowDebugText || CinemachineDebug.GameViewGuidesEnabled) + && CinemachineDebug.OnGUIHandlers != null && Event.current.type != EventType.Layout) + { + CinemachineDebug.OnGUIHandlers(this); + } + } + void OnGuiHandler(CinemachineBrain brain) { + if (!ShowDebugText && m_DebugText != null) + { + m_DebugText.Dispose(); + m_DebugText = null; + } + if (!ShowDebugText || brain != this) return; diff --git a/com.unity.cinemachine/Runtime/Debug/CinemachineDebug.cs b/com.unity.cinemachine/Runtime/Debug/CinemachineDebug.cs index 40f05ff56..2a30cda94 100644 --- a/com.unity.cinemachine/Runtime/Debug/CinemachineDebug.cs +++ b/com.unity.cinemachine/Runtime/Debug/CinemachineDebug.cs @@ -118,7 +118,7 @@ static void PositionWithinCameraView(VisualElement viewportContainer, Camera cam /// /// Delegate for OnGUI debugging. - /// This will be called by the CinemachineDebugDisplay in its OnGUI (editor only) + /// This will be called by the CinemachineDebugBrain in its OnGUI (editor only) /// public static Action OnGUIHandlers; diff --git a/com.unity.cinemachine/Runtime/Debug/CinemachineDebugDisplay.cs b/com.unity.cinemachine/Runtime/Debug/CinemachineDebugDisplay.cs deleted file mode 100644 index d1801c960..000000000 --- a/com.unity.cinemachine/Runtime/Debug/CinemachineDebugDisplay.cs +++ /dev/null @@ -1,23 +0,0 @@ -#if UNITY_EDITOR && CINEMACHINE_UIELEMENTS -using Unity.Cinemachine; -using UnityEngine; - -/// -/// This component is added to the brain game object to display debug information in the game view. -/// It is a separate component in order to avoid having OnGUI in the CinemachineBrain, which allocates garbage. -/// -[AddComponentMenu("")] // Hide in menu -[ExecuteAlways] -class CinemachineDebugDisplay : MonoBehaviour -{ - CinemachineBrain m_Brain; - - void OnGUI() - { - if (m_Brain == null) - TryGetComponent(out m_Brain); - if (m_Brain != null && CinemachineDebug.OnGUIHandlers != null && Event.current.type != EventType.Layout) - CinemachineDebug.OnGUIHandlers(m_Brain); - } -} -#endif diff --git a/com.unity.cinemachine/Runtime/Debug/CinemachineDebugDisplay.cs.meta b/com.unity.cinemachine/Runtime/Debug/CinemachineDebugDisplay.cs.meta deleted file mode 100644 index 8b2b52e25..000000000 --- a/com.unity.cinemachine/Runtime/Debug/CinemachineDebugDisplay.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: 9381c3d1a5c625d488fc74dab637c5ab \ No newline at end of file