A game about forced loneliness, made by TACStudios
1using System; 2 3namespace UnityEngine.Rendering 4{ 5 public partial class DebugUI 6 { 7 // Root panel class - we don't want to extend Container here because we need a clear 8 // separation between debug panels and actual widgets 9 /// <summary> 10 /// Root panel class. 11 /// </summary> 12 public class Panel : IContainer, IComparable<Panel> 13 { 14 /// <summary> 15 /// Widget flags for this panel. 16 /// </summary> 17 public Flags flags { get; set; } 18 /// <summary> 19 /// Display name of the panel. 20 /// </summary> 21 public string displayName { get; set; } 22 /// <summary> 23 /// Group index of the panel. 24 /// </summary> 25 public int groupIndex { get; set; } 26 /// <summary> 27 /// Path of the panel. 28 /// </summary> 29 public string queryPath { get { return displayName; } } 30 31 /// <summary> 32 /// Specify if the panel is editor only. 33 /// </summary> 34 public bool isEditorOnly { get { return (flags & Flags.EditorOnly) != 0; } } 35 /// <summary> 36 /// Specify if the panel is runtime only. 37 /// </summary> 38 public bool isRuntimeOnly { get { return (flags & Flags.RuntimeOnly) != 0; } } 39 /// <summary> 40 /// Returns true if the panel is inactive in the editor. 41 /// </summary> 42 public bool isInactiveInEditor { get { return (isRuntimeOnly && !Application.isPlaying); } } 43 /// <summary> 44 /// Returns true if the panel should always be updated. 45 /// </summary> 46 public bool editorForceUpdate { get { return (flags & Flags.EditorForceUpdate) != 0; } } 47 48 /// <summary> 49 /// List of children. 50 /// </summary> 51 public ObservableList<Widget> children { get; private set; } 52 /// <summary> 53 /// Callback used when the panel is set dirty. 54 /// </summary> 55 public event Action<Panel> onSetDirty = delegate { }; 56 57 /// <summary> 58 /// Constructor. 59 /// </summary> 60 public Panel() 61 { 62 children = new ObservableList<Widget>(); 63 children.ItemAdded += OnItemAdded; 64 children.ItemRemoved += OnItemRemoved; 65 } 66 67 /// <summary> 68 /// Callback used when a child is added. 69 /// </summary> 70 /// <param name="sender">Sender widget.</param> 71 /// <param name="e">List of added children.</param> 72 protected virtual void OnItemAdded(ObservableList<Widget> sender, ListChangedEventArgs<Widget> e) 73 { 74 if (e.item != null) 75 { 76 e.item.panel = this; 77 e.item.parent = this; 78 } 79 80 SetDirty(); 81 } 82 83 /// <summary> 84 /// Callback used when a child is removed. 85 /// </summary> 86 /// <param name="sender">Sender widget.</param> 87 /// <param name="e">List of removed children.</param> 88 protected virtual void OnItemRemoved(ObservableList<Widget> sender, ListChangedEventArgs<Widget> e) 89 { 90 if (e.item != null) 91 { 92 e.item.panel = null; 93 e.item.parent = null; 94 } 95 96 SetDirty(); 97 } 98 99 /// <summary> 100 /// Set the panel dirty. 101 /// </summary> 102 public void SetDirty() 103 { 104 int numChildren = children.Count; 105 for (int i = 0; i < numChildren; i++) 106 children[i].GenerateQueryPath(); 107 108 onSetDirty(this); 109 } 110 111 /// <summary> 112 /// Returns the hash code of the panel. 113 /// </summary> 114 /// <returns>Hash code of the panel.</returns> 115 public override int GetHashCode() 116 { 117 int hash = 17; 118 hash = hash * 23 + displayName.GetHashCode(); 119 120 121 int numChildren = children.Count; 122 for (int i = 0; i < numChildren; i++) 123 hash = hash * 23 + children[i].GetHashCode(); 124 125 return hash; 126 } 127 128 /// <summary> 129 /// Comparison function. 130 /// </summary> 131 /// <param name="other">Panel to compare to.</param> 132 /// <returns>True if the panels share the same group index.</returns> 133 int IComparable<Panel>.CompareTo(Panel other) => other == null ? 1 : groupIndex.CompareTo(other.groupIndex); 134 } 135 } 136}