From 28656f2f8add9b49e794632686007fa27175fb63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez?= Date: Thu, 21 Oct 2021 12:20:09 +0200 Subject: [PATCH 1/4] Fix serialization of DebugStateFlags of the Rendering Debugger --- .../Editor/Debugging/DebugState.cs | 41 +++++++++++++++++-- .../Editor/Debugging/DebugWindow.cs | 6 +-- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs b/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs index e28b1ed712d..dee6a4054a2 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,43 @@ 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 string m_EnumValueAsString; + + [SerializeField] + private Type m_EnumType; + + /// + /// Value of the Debug Item + /// + public override Enum value + { + get + { + if (Enum.TryParse(m_EnumType, m_EnumValueAsString, out object result)) + return (Enum)result; + + return default(Enum); + } + set + { + m_EnumValueAsString = value.ToString(); + } + } + + /// + /// Set the value of the Debug Item. + /// + /// Input value. + /// Debug Item field. + public override void SetValue(object value, DebugUI.IValueField field) + { + base.SetValue(value, field); + m_EnumType = (field as DebugUI.BitField).enumType; + } + } /// /// 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 988c0059b46..30b59ee3d7c 100644 --- a/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs +++ b/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs @@ -286,12 +286,10 @@ 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()); + widget.SetValue(state.GetValue()); } void OnUndoRedoPerformed() From 5a407358387642663f0839530fc3cb43f6169bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez?= Date: Thu, 21 Oct 2021 12:22:55 +0200 Subject: [PATCH 2/4] Changelog --- com.unity.render-pipelines.core/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.core/CHANGELOG.md b/com.unity.render-pipelines.core/CHANGELOG.md index 7e63de4d5df..81b77a7f665 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### 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.1.0] - 2021-09-23 From 9b65bd7c64dff71ca0d513d87a43e798ee07500a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez?= Date: Thu, 21 Oct 2021 12:53:16 +0200 Subject: [PATCH 3/4] Tiny refactor into a SerializableEnum class --- .../Editor/Debugging/DebugState.cs | 21 ++------- .../Runtime/Common/SerializableEnum.cs | 46 +++++++++++++++++++ .../Runtime/Common/SerializableEnum.cs.meta | 11 +++++ 3 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 com.unity.render-pipelines.core/Runtime/Common/SerializableEnum.cs create mode 100644 com.unity.render-pipelines.core/Runtime/Common/SerializableEnum.cs.meta diff --git a/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs b/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs index dee6a4054a2..06d417e61c4 100644 --- a/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs +++ b/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs @@ -147,27 +147,15 @@ public sealed class DebugStateInt : DebugState { } public sealed class DebugStateFlags : DebugState { [SerializeField] - private string m_EnumValueAsString; - - [SerializeField] - private Type m_EnumType; + private SerializableEnum m_SerializableEnum; /// /// Value of the Debug Item /// public override Enum value { - get - { - if (Enum.TryParse(m_EnumType, m_EnumValueAsString, out object result)) - return (Enum)result; - - return default(Enum); - } - set - { - m_EnumValueAsString = value.ToString(); - } + get => m_SerializableEnum?.value ?? default; + set => m_SerializableEnum.value = value; } /// @@ -177,8 +165,9 @@ public override Enum 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); - m_EnumType = (field as DebugUI.BitField).enumType; } } 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: From ef39f770ad38d7deff55c7b7cd5dd058cfa2d232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez?= Date: Thu, 21 Oct 2021 12:55:33 +0200 Subject: [PATCH 4/4] format --- com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs b/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs index 30b59ee3d7c..f76f02a4c7d 100644 --- a/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs +++ b/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs @@ -289,7 +289,7 @@ void ApplyState(string queryPath, DebugState state) if (!(DebugManager.instance.GetItem(queryPath) is DebugUI.IValueField widget)) return; - widget.SetValue(state.GetValue()); + widget.SetValue(state.GetValue()); } void OnUndoRedoPerformed()