A game about forced loneliness, made by TACStudios
1using System;
2using System.Diagnostics;
3using UnityEngine.Rendering.UI;
4
5#if UNITY_EDITOR
6using UnityEditor;
7#endif
8
9#if UNITY_ANDROID || UNITY_IPHONE || UNITY_TVOS || UNITY_SWITCH
10using UnityEngine.UI;
11#endif
12
13namespace UnityEngine.Rendering
14{
15 using UnityObject = UnityEngine.Object;
16
17 public sealed partial class DebugManager
18 {
19 /// <summary>
20 /// The modes of the UI of the Rendering Debugger
21 /// </summary>
22 public enum UIMode : int
23 {
24 /// <summary>
25 /// Editor Window
26 /// </summary>
27 EditorMode,
28 /// <summary>
29 /// In Game view
30 /// </summary>
31 RuntimeMode
32 }
33
34 /// <summary>
35 /// Event that is raised when a window state is changed
36 /// </summary>
37 public static event Action<UIMode, bool> windowStateChanged;
38
39 class UIState
40 {
41 public UIMode mode;
42
43 [SerializeField]
44 private bool m_Open;
45 public bool open
46 {
47 get => m_Open;
48 set
49 {
50 if (m_Open == value)
51 return;
52
53 m_Open = value;
54
55 windowStateChanged?.Invoke(mode, m_Open);
56 }
57 }
58 }
59
60 private UIState editorUIState = new UIState() { mode = UIMode.EditorMode };
61
62 /// <summary>
63 /// Is the debug editor window open.
64 /// </summary>
65 public bool displayEditorUI
66 {
67 get => editorUIState.open;
68 set => editorUIState.open = value;
69 }
70
71 private bool m_EnableRuntimeUI = true;
72
73 /// <summary>
74 /// Controls whether runtime UI can be enabled. When this is set to false, there will be no overhead
75 /// from debug GameObjects or runtime initialization.
76 /// </summary>
77 public bool enableRuntimeUI
78 {
79 get => m_EnableRuntimeUI;
80 set
81 {
82 if (value != m_EnableRuntimeUI)
83 {
84 m_EnableRuntimeUI = value;
85 DebugUpdater.SetEnabled(value);
86 }
87 }
88 }
89
90 private UIState runtimeUIState = new UIState() { mode = UIMode.RuntimeMode };
91
92 /// <summary>
93 /// Displays the runtime version of the debug window.
94 /// </summary>
95 public bool displayRuntimeUI
96 {
97 get => m_Root != null && m_Root.activeInHierarchy;
98 set
99 {
100 if (value)
101 {
102 m_Root = UnityObject.Instantiate(Resources.Load<Transform>("DebugUICanvas")).gameObject;
103 m_Root.name = "[Debug Canvas]";
104 m_Root.transform.localPosition = Vector3.zero;
105 m_RootUICanvas = m_Root.GetComponent<DebugUIHandlerCanvas>();
106
107#if UNITY_ANDROID || UNITY_IPHONE || UNITY_TVOS || UNITY_SWITCH
108 var canvasScaler = m_Root.GetComponent<CanvasScaler>();
109 canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
110#endif
111
112 m_Root.SetActive(true);
113 }
114 else
115 {
116 CoreUtils.Destroy(m_Root);
117 m_Root = null;
118 m_RootUICanvas = null;
119 }
120
121 onDisplayRuntimeUIChanged(value);
122 DebugUpdater.HandleInternalEventSystemComponents(value);
123
124 runtimeUIState.open = m_Root != null && m_Root.activeInHierarchy;
125 }
126 }
127
128 /// <summary>
129 /// Displays the persistent runtime debug window.
130 /// </summary>
131 public bool displayPersistentRuntimeUI
132 {
133 get => m_RootUIPersistentCanvas != null && m_PersistentRoot.activeInHierarchy;
134 set
135 {
136 if (value)
137 {
138 EnsurePersistentCanvas();
139 }
140 else
141 {
142 CoreUtils.Destroy(m_PersistentRoot);
143 m_PersistentRoot = null;
144 m_RootUIPersistentCanvas = null;
145 }
146 }
147 }
148 }
149}
150