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
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
;
38 DebugUIHandlerCanvas m_RootUICanvas
;
40 GameObject m_PersistentRoot
;
41 DebugUIHandlerPersistentCanvas m_RootUIPersistentCanvas
;
43 public bool displayRuntimeUI
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
;
59 if (value && m_Root
== null)
61 var uiManager
= UnityObject
.FindObjectOfType
<DebugUIHandlerCanvas
>();
63 if (uiManager
!= null)
65 m_Root
= uiManager
.gameObject
;
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
>();
76 m_Root
.SetActive(value);
78 onDisplayRuntimeUIChanged(value);
82 public bool displayPersistentRuntimeUI
84 get { return m_RootUIPersistentCanvas != null && m_PersistentRoot.activeInHierarchy; }
87 CheckPersistentCanvas();
88 m_PersistentRoot
.SetActive(value);
98 public void RefreshEditor()
100 refreshEditorRequested
= true;
105 if (m_Panels
!= null)
109 public int GetState()
113 foreach (var panel
in m_Panels
)
114 hash
= hash
* 23 + panel
.GetHashCode();
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
;
138 m_PersistentRoot
= uiManager
.gameObject
;
141 m_RootUIPersistentCanvas
= m_PersistentRoot
.GetComponent
<DebugUIHandlerPersistentCanvas
>();
145 public void TogglePersistent(DebugUI
.Widget widget
)
150 var valueWidget
= widget
as DebugUI
.Value
;
151 if (valueWidget
== null)
153 Debug
.Log("Only DebugUI.Value items can be made persistent.");
157 CheckPersistentCanvas();
158 m_RootUIPersistentCanvas
.Toggle(valueWidget
);
161 void OnPanelDirty(DebugUI
.Panel panel
)
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
)
175 DebugUI
.Panel p
= null;
179 p
= new DebugUI
.Panel { displayName = displayName }
;
180 p
.onSetDirty
+= OnPanelDirty
;
182 m_ReadOnlyPanels
= m_Panels
.AsReadOnly();
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
;
206 public void RemovePanel(DebugUI
.Panel panel
)
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
);
227 DebugUI
.Widget
GetItem(string queryPath
, DebugUI
.IContainer container
)
229 foreach (var child
in container
.children
)
231 if (child
.queryPath
== queryPath
)
234 var containerChild
= child
as DebugUI
.IContainer
;
235 if (containerChild
!= null)
237 var w
= GetItem(queryPath
, containerChild
);