DebugUI.Panel.cs 4.6 KB

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