diff --git a/com.unity.render-pipelines.core/CHANGELOG.md b/com.unity.render-pipelines.core/CHANGELOG.md index 3d874c801aa..f0f54079716 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -32,6 +32,7 @@ The version number for this package has increased due to a version update of a r ### Fixed - Fixed black pixel issue in AMD FidelityFX RCAS implementation - Fixed a critical issue on android devices & lens flares. Accidentally creating a 16 bit texture was causing gpus not supporting them to fail. +- Fixed serialization of DebugStateFlags, the internal Enum was not being serialized. ## [12.0.0] - 2021-01-11 diff --git a/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs b/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs index e28b1ed712d..06d417e61c4 100644 --- a/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs +++ b/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs @@ -104,8 +104,7 @@ public override int GetHashCode() { int hash = 13; hash = hash * 23 + m_QueryPath.GetHashCode(); - if (m_Value != null) - hash = hash * 23 + m_Value.GetHashCode(); + hash = hash * 23 + value.GetHashCode(); return hash; } } @@ -145,7 +144,32 @@ public sealed class DebugStateInt : DebugState { } /// Flags Debug State. /// [Serializable, DebugState(typeof(DebugUI.BitField))] - public sealed class DebugStateFlags : DebugState { } + public sealed class DebugStateFlags : DebugState + { + [SerializeField] + private SerializableEnum m_SerializableEnum; + + /// + /// Value of the Debug Item + /// + public override Enum value + { + get => m_SerializableEnum?.value ?? default; + set => m_SerializableEnum.value = value; + } + + /// + /// Set the value of the Debug Item. + /// + /// Input value. + /// Debug Item field. + public override void SetValue(object value, DebugUI.IValueField field) + { + if (m_SerializableEnum == null) + m_SerializableEnum = new SerializableEnum((field as DebugUI.BitField).enumType); + base.SetValue(value, field); + } + } /// /// Unsigned Integer Debug State. diff --git a/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs b/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs index 09c64db15be..83b39d332c8 100644 --- a/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs +++ b/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs @@ -286,9 +286,7 @@ public void ApplyStates(bool forceApplyAll = false) void ApplyState(string queryPath, DebugState state) { - if (state == null || - state.GetValue() == null || - !(DebugManager.instance.GetItem(queryPath) is DebugUI.IValueField widget)) + if (!(DebugManager.instance.GetItem(queryPath) is DebugUI.IValueField widget)) return; widget.SetValue(state.GetValue()); diff --git a/com.unity.render-pipelines.core/Runtime/Common/SerializableEnum.cs b/com.unity.render-pipelines.core/Runtime/Common/SerializableEnum.cs new file mode 100644 index 00000000000..5af08d3f74a --- /dev/null +++ b/com.unity.render-pipelines.core/Runtime/Common/SerializableEnum.cs @@ -0,0 +1,46 @@ +namespace UnityEngine.Rendering +{ + using System; + using UnityEngine; + + /// + /// Class to serizalize Enum as string and recover it's state + /// + [Serializable] + public class SerializableEnum + { + [SerializeField] + private string m_EnumValueAsString; + + [SerializeField] + private Type m_EnumType; + + /// + /// Value of enum + /// + public Enum value + { + get + { + if (Enum.TryParse(m_EnumType, m_EnumValueAsString, out object result)) + return (Enum)result; + + return default(Enum); + } + set + { + m_EnumValueAsString = value.ToString(); + } + } + + /// + /// Construct an enum to be serialized with a type + /// + /// The underliying type of the enum + public SerializableEnum(Type enumType) + { + m_EnumType = enumType; + m_EnumValueAsString = Enum.GetNames(enumType)[0]; + } + } +} diff --git a/com.unity.render-pipelines.core/Runtime/Common/SerializableEnum.cs.meta b/com.unity.render-pipelines.core/Runtime/Common/SerializableEnum.cs.meta new file mode 100644 index 00000000000..b9bfc2bb5cb --- /dev/null +++ b/com.unity.render-pipelines.core/Runtime/Common/SerializableEnum.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7bbce3ae0d13a4240a1d7531d1e00b3d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: