A game about forced loneliness, made by TACStudios
1using System; 2using UnityEngine; 3using UnityEngine.Rendering; 4 5namespace UnityEditor.Rendering 6{ 7 /// <summary> 8 /// Serialized state of a Debug Item. 9 /// </summary> 10 [Serializable] 11 public abstract class DebugState : ScriptableObject 12 { 13 /// <summary> 14 /// Path of the Debug Item. 15 /// </summary> 16 [SerializeField] 17 protected string m_QueryPath; 18 19 // We need this to keep track of the state modified in the current frame. 20 // This helps reduces the cost of re-applying states to original widgets and is also needed 21 // when two states point to the same value (e.g. when using split enums like HDRP does for 22 // the `fullscreenDebugMode`. 23 internal static DebugState m_CurrentDirtyState; 24 25 /// <summary> 26 /// Path of the Debug Item. 27 /// </summary> 28 public string queryPath 29 { 30 get { return m_QueryPath; } 31 internal set { m_QueryPath = value; } 32 } 33 34 /// <summary> 35 /// Returns the value of the Debug Item. 36 /// </summary> 37 /// <returns>Value of the Debug Item.</returns> 38 public abstract object GetValue(); 39 40 /// <summary> 41 /// Set the value of the Debug Item. 42 /// </summary> 43 /// <param name="value">Input value.</param> 44 /// <param name="field">Debug Item field.</param> 45 public abstract void SetValue(object value, DebugUI.IValueField field); 46 47 /// <summary> 48 /// OnEnable implementation. 49 /// </summary> 50 public virtual void OnEnable() 51 { 52 hideFlags = HideFlags.HideAndDontSave; 53 } 54 } 55 56 /// <summary> 57 /// Generic serialized state of a Debug Item. 58 /// </summary> 59 /// <typeparam name="T">The type of the Debug Item.</typeparam> 60 [Serializable] 61 public class DebugState<T> : DebugState 62 { 63 /// <summary> 64 /// Value of the Debug Item. 65 /// </summary> 66 [SerializeField] 67 protected T m_Value; 68 69 /// <summary> 70 /// Value of the Debug Item 71 /// </summary> 72 public virtual T value 73 { 74 get { return m_Value; } 75 set { m_Value = value; } 76 } 77 78 /// <summary> 79 /// Returns the value of the Debug Item. 80 /// </summary> 81 /// <returns>Value of the Debug Item.</returns> 82 public override object GetValue() 83 { 84 return value; 85 } 86 87 /// <summary> 88 /// Set the value of the Debug Item. 89 /// </summary> 90 /// <param name="value">Input value.</param> 91 /// <param name="field">Debug Item field.</param> 92 public override void SetValue(object value, DebugUI.IValueField field) 93 { 94 this.value = (T)field.ValidateValue(value); 95 } 96 97 /// <summary> 98 /// Returns the hash code of the Debug Item. 99 /// </summary> 100 /// <returns>Hash code of the Debug Item</returns> 101 public override int GetHashCode() 102 { 103 unchecked 104 { 105 int hash = 13; 106 hash = hash * 23 + m_QueryPath.GetHashCode(); 107 if (value != null) 108 hash = hash * 23 + value.GetHashCode(); 109 110 return hash; 111 } 112 } 113 } 114 115 /// <summary> 116 /// Attribute specifying which types should be save as this Debug State. 117 /// </summary> 118 public sealed class DebugStateAttribute : Attribute 119 { 120 internal readonly Type[] types; 121 122 /// <summary> 123 /// Debug State Attribute constructor 124 /// </summary> 125 /// <param name="types">List of types of the Debug State.</param> 126 public DebugStateAttribute(params Type[] types) 127 { 128 this.types = types; 129 } 130 } 131 132 // Builtins 133 /// <summary> 134 /// Boolean Debug State. 135 /// </summary> 136 [Serializable, DebugState(typeof(DebugUI.BoolField), typeof(DebugUI.Foldout), typeof(DebugUI.HistoryBoolField))] 137 public sealed class DebugStateBool : DebugState<bool> { } 138 139 /// <summary> 140 /// Enums Debug State. 141 /// </summary> 142 [Serializable, DebugState(typeof(DebugUI.EnumField), typeof(DebugUI.HistoryEnumField))] 143 public sealed class DebugStateEnum : DebugState<int> 144 { 145 DebugUI.EnumField m_EnumField; 146 147 /// <summary> 148 /// Set the value of the Debug Item. 149 /// </summary> 150 /// <param name="value">Input value.</param> 151 /// <param name="field">Debug Item field.</param> 152 public override void SetValue(object value, DebugUI.IValueField field) 153 { 154 m_EnumField = field as DebugUI.EnumField; 155 base.SetValue(value, field); 156 } 157 158 /// <summary> 159 /// On Enable method from <see cref="ScriptableObject"/> 160 /// </summary> 161 public override void OnEnable() 162 { 163 base.OnEnable(); 164 165 if (m_EnumField == null) 166 return; 167 168 m_EnumField.SetValue(value); 169 base.SetValue(value, m_EnumField); 170 } 171 } 172 173 /// <summary> 174 /// Integer Debug State. 175 /// </summary> 176 [Serializable, DebugState(typeof(DebugUI.IntField))] 177 public sealed class DebugStateInt : DebugState<int> { } 178 179 /// <summary> 180 /// Object Debug State. 181 /// </summary> 182 [Serializable, DebugState(typeof(DebugUI.ObjectPopupField))] 183 public sealed class DebugStateObject : DebugState<UnityEngine.Object> 184 { 185 /// <summary> 186 /// Returns the hash code of the Debug Item. 187 /// </summary> 188 /// <returns>Hash code of the Debug Item</returns> 189 public override int GetHashCode() 190 { 191 unchecked 192 { 193 int hash = 13; 194 hash = hash * 23 + m_QueryPath.GetHashCode(); 195 196 if (value != null) 197 { 198 hash = hash * 23 + value.GetHashCode(); 199 } 200 201 return hash; 202 } 203 } 204 } 205 206 /// <summary> 207 /// Flags Debug State. 208 /// </summary> 209 [Serializable, DebugState(typeof(DebugUI.BitField))] 210 public sealed class DebugStateFlags : DebugState<Enum> 211 { 212 [SerializeField] 213 private SerializableEnum m_SerializableEnum; 214 215 /// <summary> 216 /// Value of the Debug Item 217 /// </summary> 218 public override Enum value 219 { 220 get => m_SerializableEnum?.value ?? default; 221 set => m_SerializableEnum.value = value; 222 } 223 224 /// <summary> 225 /// Set the value of the Debug Item. 226 /// </summary> 227 /// <param name="value">Input value.</param> 228 /// <param name="field">Debug Item field.</param> 229 public override void SetValue(object value, DebugUI.IValueField field) 230 { 231 if (m_SerializableEnum == null) 232 m_SerializableEnum = new SerializableEnum((field as DebugUI.BitField).enumType); 233 base.SetValue(value, field); 234 } 235 } 236 237 /// <summary> 238 /// Unsigned Integer Debug State. 239 /// </summary> 240 [Serializable, DebugState(typeof(DebugUI.UIntField), typeof(DebugUI.MaskField))] 241 public sealed class DebugStateUInt : DebugState<uint> { } 242 243 /// <summary> 244 /// Float Debug State. 245 /// </summary> 246 [Serializable, DebugState(typeof(DebugUI.FloatField))] 247 public sealed class DebugStateFloat : DebugState<float> { } 248 249 /// <summary> 250 /// Color Debug State. 251 /// </summary> 252 [Serializable, DebugState(typeof(DebugUI.ColorField))] 253 public sealed class DebugStateColor : DebugState<Color> { } 254 255 /// <summary> 256 /// Vector2 Debug State. 257 /// </summary> 258 [Serializable, DebugState(typeof(DebugUI.Vector2Field))] 259 public sealed class DebugStateVector2 : DebugState<Vector2> { } 260 261 /// <summary> 262 /// Vector3 Debug State. 263 /// </summary> 264 [Serializable, DebugState(typeof(DebugUI.Vector3Field))] 265 public sealed class DebugStateVector3 : DebugState<Vector3> { } 266 267 /// <summary> 268 /// Vector4 Debug State. 269 /// </summary> 270 [Serializable, DebugState(typeof(DebugUI.Vector4Field))] 271 public sealed class DebugStateVector4 : DebugState<Vector4> { } 272}