DebugUI.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System;
  2. using UnityEngine.Assertions;
  3. namespace UnityEngine.Rendering
  4. {
  5. /// <summary>
  6. /// Debug UI Class
  7. /// </summary>
  8. public partial class DebugUI
  9. {
  10. /// <summary>
  11. /// Flags for Debug UI widgets.
  12. /// </summary>
  13. [Flags]
  14. public enum Flags
  15. {
  16. /// <summary>
  17. /// None.
  18. /// </summary>
  19. None = 0,
  20. /// <summary>
  21. /// This widget is Editor only.
  22. /// </summary>
  23. EditorOnly = 1 << 1,
  24. /// <summary>
  25. /// This widget is Runtime only.
  26. /// </summary>
  27. RuntimeOnly = 1 << 2,
  28. /// <summary>
  29. /// This widget will force the Debug Editor Window refresh.
  30. /// </summary>
  31. EditorForceUpdate = 1 << 3
  32. }
  33. /// <summary>
  34. /// Base class for all debug UI widgets.
  35. /// </summary>
  36. public abstract class Widget
  37. {
  38. // Set to null until it's added to a panel, be careful
  39. /// <summary>
  40. /// Panels containing the widget.
  41. /// </summary>
  42. protected Panel m_Panel;
  43. /// <summary>
  44. /// Panels containing the widget.
  45. /// </summary>
  46. public virtual Panel panel
  47. {
  48. get { return m_Panel; }
  49. internal set { m_Panel = value; }
  50. }
  51. /// <summary>
  52. /// Parent container.
  53. /// </summary>
  54. protected IContainer m_Parent;
  55. /// <summary>
  56. /// Parent container.
  57. /// </summary>
  58. public virtual IContainer parent
  59. {
  60. get { return m_Parent; }
  61. internal set { m_Parent = value; }
  62. }
  63. /// <summary>
  64. /// Flags for the widget.
  65. /// </summary>
  66. public Flags flags { get; set; }
  67. /// <summary>
  68. /// Display name.
  69. /// </summary>
  70. public string displayName { get; set; }
  71. /// <summary>
  72. /// Path of the widget.
  73. /// </summary>
  74. public string queryPath { get; private set; }
  75. /// <summary>
  76. /// True if the widget is Editor only.
  77. /// </summary>
  78. public bool isEditorOnly { get { return (flags & Flags.EditorOnly) != 0; } }
  79. /// <summary>
  80. /// True if the widget is Runtime only.
  81. /// </summary>
  82. public bool isRuntimeOnly { get { return (flags & Flags.RuntimeOnly) != 0; } }
  83. /// <summary>
  84. /// True if the widget is inactive in the editor (ie: widget is runtime only and the application is not 'Playing')
  85. /// </summary>
  86. public bool isInactiveInEditor { get { return (isRuntimeOnly && !Application.isPlaying); } }
  87. internal virtual void GenerateQueryPath()
  88. {
  89. queryPath = displayName.Trim();
  90. if (m_Parent != null)
  91. queryPath = m_Parent.queryPath + " -> " + queryPath;
  92. }
  93. /// <summary>
  94. /// Returns the hash code of the widget.
  95. /// </summary>
  96. /// <returns>The hash code of the widget.</returns>
  97. public override int GetHashCode()
  98. {
  99. return queryPath.GetHashCode();
  100. }
  101. }
  102. /// <summary>
  103. /// Interface for widgets that can contain other widgets.
  104. /// </summary>
  105. public interface IContainer
  106. {
  107. /// <summary>
  108. /// List of children of the container.
  109. /// </summary>
  110. ObservableList<Widget> children { get; }
  111. /// <summary>
  112. /// Display name of the container.
  113. /// </summary>
  114. string displayName { get; set; }
  115. /// <summary>
  116. /// Path of the container.
  117. /// </summary>
  118. string queryPath { get; }
  119. }
  120. /// <summary>
  121. /// Any widget that implements this will be considered for serialization (only if the setter is set and thus is not read-only)
  122. /// </summary>
  123. public interface IValueField
  124. {
  125. /// <summary>
  126. /// Return the value of the field.
  127. /// </summary>
  128. /// <returns>Value of the field.</returns>
  129. object GetValue();
  130. /// <summary>
  131. /// Set the value of the field.
  132. /// </summary>
  133. /// <param name="value">Input value.</param>
  134. void SetValue(object value);
  135. /// <summary>
  136. /// Function used to validate the value when setting it.
  137. /// </summary>
  138. /// <param name="value"></param>
  139. /// <returns></returns>
  140. object ValidateValue(object value);
  141. }
  142. // Miscellaneous
  143. /// <summary>
  144. /// Button widget.
  145. /// </summary>
  146. public class Button : Widget
  147. {
  148. /// <summary>
  149. /// Action performed by the button.
  150. /// </summary>
  151. public Action action { get; set; }
  152. }
  153. /// <summary>
  154. /// Read only Value widget.
  155. /// </summary>
  156. public class Value : Widget
  157. {
  158. /// <summary>
  159. /// Getter for the Value.
  160. /// </summary>
  161. public Func<object> getter { get; set; }
  162. /// <summary>
  163. /// Refresh rate for the read-only value (runtime only)
  164. /// </summary>
  165. public float refreshRate = 0.1f;
  166. /// <summary>
  167. /// Returns the value of the widget.
  168. /// </summary>
  169. /// <returns>The value of the widget.</returns>
  170. public object GetValue()
  171. {
  172. Assert.IsNotNull(getter);
  173. return getter();
  174. }
  175. }
  176. }
  177. }