#if ENABLE_UIELEMENTS_MODULE && UNITY_ENABLE_CHECKS #define ENABLE_RENDERING_DEBUGGER_UI #endif #if ENABLE_INPUT_SYSTEM && ENABLE_INPUT_SYSTEM_PACKAGE #define USE_INPUT_SYSTEM #endif using System; namespace UnityEngine.Rendering { public sealed partial class DebugManager { /// /// The modes of the UI of the Rendering Debugger /// public enum UIMode : int { /// /// Editor Window /// EditorMode, /// /// In Game view /// RuntimeMode } /// /// Event that is raised when a window state is changed /// public static event Action windowStateChanged; class UIState { public UIMode mode; bool m_Open; public bool open { get => m_Open; set { if (m_Open == value) return; m_Open = value; windowStateChanged?.Invoke(mode, m_Open); } } } readonly UIState m_EditorUIState = new UIState() { mode = UIMode.EditorMode }; /// /// Is the debug editor window open. /// public bool displayEditorUI { get => m_EditorUIState.open; set => m_EditorUIState.open = value; } bool m_EnableRuntimeUI = true; /// /// Controls whether runtime UI can be enabled. When this is set to false, there will be no overhead /// from debug GameObjects or runtime initialization. /// public bool enableRuntimeUI { get => m_EnableRuntimeUI; set { if (value != m_EnableRuntimeUI) { m_EnableRuntimeUI = value; DebugUpdater.SetEnabled(value); } } } readonly UIState m_RuntimeUIState = new UIState() { mode = UIMode.RuntimeMode }; /// /// Displays the runtime version of the debug window. /// public bool displayRuntimeUI { #if ENABLE_RENDERING_DEBUGGER_UI get => m_RuntimeDebugWindow != null && m_RuntimeDebugWindow.gameObject.activeInHierarchy; set { if (value) { if (m_RuntimeDebugWindow == null && GraphicsSettings.TryGetRenderPipelineSettings(out _)) { var go = new GameObject("[Debug UI]"); m_RuntimeDebugWindow = go.AddComponent(); go.SetActive(true); } #if USE_INPUT_SYSTEM m_DebugMenuActions.Enable(); #endif } else { if (m_RuntimeDebugWindow != null) { CoreUtils.Destroy(m_RuntimeDebugWindow.gameObject); m_RuntimeDebugWindow = null; } #if USE_INPUT_SYSTEM m_DebugMenuActions.Disable(); #endif } onDisplayRuntimeUIChanged(value); m_RuntimeUIState.open = m_RuntimeDebugWindow != null && m_RuntimeDebugWindow.gameObject.activeInHierarchy; } #else get => false; set { if (value) throw new NotSupportedException("Rendering Debugger Runtime UI requires the UIElements module."); } #endif } /// /// Displays the persistent runtime debug window. /// public bool displayPersistentRuntimeUI { #if ENABLE_RENDERING_DEBUGGER_UI get => m_RuntimePersistentDebugUI != null && m_RuntimePersistentDebugUI.gameObject.activeInHierarchy; set { if (value) { if (m_RuntimePersistentDebugUI == null && GraphicsSettings.TryGetRenderPipelineSettings(out _)) { var go = new GameObject("[Persistent Debug UI]"); m_RuntimePersistentDebugUI = go.AddComponent(); go.SetActive(true); } } else { CoreUtils.Destroy(m_RuntimePersistentDebugUI?.gameObject); m_RuntimePersistentDebugUI = null; } } #else get => false; set { if (value) throw new NotSupportedException("Rendering Debugger Runtime UI requires the UIElements module."); } #endif } } }