post processing
[WindSway-HDRP.git] / Library / PackageCache / com.unity.render-pipelines.high-definition@4.10.0-preview / Runtime / Core / Debugging / DebugManager.cs
blobeab723f765c039f32a41e0993a576afd485004dd
1 using System;
2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using UnityEngine.Experimental.Rendering.UI;
6 namespace UnityEngine.Experimental.Rendering
8 using UnityObject = UnityEngine.Object;
10 public sealed partial class DebugManager
12 static readonly DebugManager s_Instance = new DebugManager();
13 public static DebugManager instance { get { return s_Instance; } }
15 // Explicit static constructor to tell the C# compiler not to mark type as beforefieldinit
16 static DebugManager() {}
18 ReadOnlyCollection<DebugUI.Panel> m_ReadOnlyPanels;
19 readonly List<DebugUI.Panel> m_Panels = new List<DebugUI.Panel>();
21 public ReadOnlyCollection<DebugUI.Panel> panels
23 get
25 if (m_ReadOnlyPanels == null)
26 m_ReadOnlyPanels = m_Panels.AsReadOnly();
28 return m_ReadOnlyPanels;
32 public event Action<bool> onDisplayRuntimeUIChanged = delegate {};
33 public event Action onSetDirty = delegate {};
35 public bool refreshEditorRequested;
37 GameObject m_Root;
38 DebugUIHandlerCanvas m_RootUICanvas;
40 GameObject m_PersistentRoot;
41 DebugUIHandlerPersistentCanvas m_RootUIPersistentCanvas;
43 public bool displayRuntimeUI
45 get
47 var uiManager = UnityObject.FindObjectOfType<DebugUIHandlerCanvas>();
49 // Might be needed to update the reference after domain reload
50 if (uiManager != null)
52 m_Root = uiManager.gameObject;
55 return m_Root != null && m_Root.activeInHierarchy;
57 set
59 if (value && m_Root == null)
61 var uiManager = UnityObject.FindObjectOfType<DebugUIHandlerCanvas>();
63 if (uiManager != null)
65 m_Root = uiManager.gameObject;
66 return;
69 m_Root = UnityObject.Instantiate(Resources.Load<Transform>("DebugUI Canvas")).gameObject;
70 m_Root.name = "[Debug Canvas]";
71 m_Root.transform.localPosition = Vector3.zero;
72 m_RootUICanvas = m_Root.GetComponent<DebugUIHandlerCanvas>();
75 if (m_Root != null)
76 m_Root.SetActive(value);
78 onDisplayRuntimeUIChanged(value);
82 public bool displayPersistentRuntimeUI
84 get { return m_RootUIPersistentCanvas != null && m_PersistentRoot.activeInHierarchy; }
85 set
87 CheckPersistentCanvas();
88 m_PersistentRoot.SetActive(value);
92 DebugManager()
94 RegisterInputs();
95 RegisterActions();
98 public void RefreshEditor()
100 refreshEditorRequested = true;
103 public void Reset()
105 if (m_Panels != null)
106 m_Panels.Clear();
109 public int GetState()
111 int hash = 17;
113 foreach (var panel in m_Panels)
114 hash = hash * 23 + panel.GetHashCode();
116 return hash;
119 internal void ChangeSelection(DebugUIHandlerWidget widget, bool fromNext)
121 m_RootUICanvas.ChangeSelection(widget, fromNext);
124 void CheckPersistentCanvas()
126 if (m_RootUIPersistentCanvas == null)
128 var uiManager = UnityObject.FindObjectOfType<DebugUIHandlerPersistentCanvas>();
130 if (uiManager == null)
132 m_PersistentRoot = UnityObject.Instantiate(Resources.Load<Transform>("DebugUI Persistent Canvas")).gameObject;
133 m_PersistentRoot.name = "[Debug Canvas - Persistent]";
134 m_PersistentRoot.transform.localPosition = Vector3.zero;
136 else
138 m_PersistentRoot = uiManager.gameObject;
141 m_RootUIPersistentCanvas = m_PersistentRoot.GetComponent<DebugUIHandlerPersistentCanvas>();
145 public void TogglePersistent(DebugUI.Widget widget)
147 if (widget == null)
148 return;
150 var valueWidget = widget as DebugUI.Value;
151 if (valueWidget == null)
153 Debug.Log("Only DebugUI.Value items can be made persistent.");
154 return;
157 CheckPersistentCanvas();
158 m_RootUIPersistentCanvas.Toggle(valueWidget);
161 void OnPanelDirty(DebugUI.Panel panel)
163 onSetDirty();
166 // TODO: Optimally we should use a query path here instead of a display name
167 public DebugUI.Panel GetPanel(string displayName, bool createIfNull = false)
169 foreach (var panel in m_Panels)
171 if (panel.displayName == displayName)
172 return panel;
175 DebugUI.Panel p = null;
177 if (createIfNull)
179 p = new DebugUI.Panel { displayName = displayName };
180 p.onSetDirty += OnPanelDirty;
181 m_Panels.Add(p);
182 m_ReadOnlyPanels = m_Panels.AsReadOnly();
185 return p;
188 // TODO: Use a query path here as well instead of a display name
189 public void RemovePanel(string displayName)
191 DebugUI.Panel panel = null;
193 foreach (var p in m_Panels)
195 if (p.displayName == displayName)
197 p.onSetDirty -= OnPanelDirty;
198 panel = p;
199 break;
203 RemovePanel(panel);
206 public void RemovePanel(DebugUI.Panel panel)
208 if (panel == null)
209 return;
211 m_Panels.Remove(panel);
212 m_ReadOnlyPanels = m_Panels.AsReadOnly();
215 public DebugUI.Widget GetItem(string queryPath)
217 foreach (var panel in m_Panels)
219 var w = GetItem(queryPath, panel);
220 if (w != null)
221 return w;
224 return null;
227 DebugUI.Widget GetItem(string queryPath, DebugUI.IContainer container)
229 foreach (var child in container.children)
231 if (child.queryPath == queryPath)
232 return child;
234 var containerChild = child as DebugUI.IContainer;
235 if (containerChild != null)
237 var w = GetItem(queryPath, containerChild);
238 if (w != null)
239 return w;
243 return null;