using System;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering
{
///
/// Serialized state of a Debug Item.
///
[Serializable]
public abstract class DebugState : ScriptableObject
{
///
/// Path of the Debug Item.
///
[SerializeField]
protected string m_QueryPath;
// We need this to keep track of the state modified in the current frame.
// This helps reduces the cost of re-applying states to original widgets and is also needed
// when two states point to the same value (e.g. when using split enums like HDRP does for
// the `fullscreenDebugMode`.
internal static DebugState m_CurrentDirtyState;
///
/// Path of the Debug Item.
///
public string queryPath
{
get { return m_QueryPath; }
internal set { m_QueryPath = value; }
}
///
/// Returns the value of the Debug Item.
///
/// Value of the Debug Item.
public abstract object GetValue();
///
/// Set the value of the Debug Item.
///
/// Input value.
/// Debug Item field.
public abstract void SetValue(object value, DebugUI.IValueField field);
///
/// OnEnable implementation.
///
public virtual void OnEnable()
{
hideFlags = HideFlags.HideAndDontSave;
}
}
///
/// Generic serialized state of a Debug Item.
///
///
[Serializable]
public class DebugState : DebugState
{
///
/// Value of the Debug Item.
///
[SerializeField]
protected T m_Value;
///
/// Value of the Debug Item
///
public virtual T value
{
get { return m_Value; }
set { m_Value = value; }
}
///
/// Returns the value of the Debug Item.
///
/// Value of the Debug Item.
public override object GetValue()
{
return value;
}
///
/// Set the value of the Debug Item.
///
/// Input value.
/// Debug Item field.
public override void SetValue(object value, DebugUI.IValueField field)
{
this.value = (T)field.ValidateValue(value);
}
///
/// Returns the hash code of the Debug Item.
///
/// Hash code of the Debug Item
public override int GetHashCode()
{
unchecked
{
int hash = 13;
hash = hash * 23 + m_QueryPath.GetHashCode();
hash = hash * 23 + m_Value.GetHashCode();
return hash;
}
}
}
///
/// Attribute specifying which types should be save as this Debug State.
///
public sealed class DebugStateAttribute : Attribute
{
internal readonly Type[] types;
///
/// Debug State Attribute constructor
///
/// List of types of the Debug State.
public DebugStateAttribute(params Type[] types)
{
this.types = types;
}
}
// Builtins
///
/// Boolean Debug State.
///
[Serializable, DebugState(typeof(DebugUI.BoolField), typeof(DebugUI.Foldout), typeof(DebugUI.HistoryBoolField))]
public sealed class DebugStateBool : DebugState {}
///
/// Integer Debug State.
///
[Serializable, DebugState(typeof(DebugUI.IntField), typeof(DebugUI.EnumField), typeof(DebugUI.HistoryEnumField))]
public sealed class DebugStateInt : DebugState {}
///
/// Flags Debug State.
///
[Serializable, DebugState(typeof(DebugUI.BitField))]
public sealed class DebugStateFlags : DebugState { }
///
/// Unsigned Integer Debug State.
///
[Serializable, DebugState(typeof(DebugUI.UIntField))]
public sealed class DebugStateUInt : DebugState {}
///
/// Float Debug State.
///
[Serializable, DebugState(typeof(DebugUI.FloatField))]
public sealed class DebugStateFloat : DebugState {}
///
/// Color Debug State.
///
[Serializable, DebugState(typeof(DebugUI.ColorField))]
public sealed class DebugStateColor : DebugState {}
///
/// Vector2 Debug State.
///
[Serializable, DebugState(typeof(DebugUI.Vector2Field))]
public sealed class DebugStateVector2 : DebugState {}
///
/// Vector3 Debug State.
///
[Serializable, DebugState(typeof(DebugUI.Vector3Field))]
public sealed class DebugStateVector3 : DebugState {}
///
/// Vector4 Debug State.
///
[Serializable, DebugState(typeof(DebugUI.Vector4Field))]
public sealed class DebugStateVector4 : DebugState {}
}