From d83fa9b4722ddff45ea4693ced4c09d91d25b555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez?= Date: Thu, 16 Dec 2021 13:05:41 +0100 Subject: [PATCH 1/2] [RPW]Fix undo for DebugUI.Enum fields on the rendering debugger. --- com.unity.render-pipelines.core/CHANGELOG.md | 1 + .../Editor/Debugging/DebugState.cs | 43 ++++++++++++++++++- .../Debugging/DebugUIDrawer.Builtins.cs | 2 +- .../Editor/Debugging/DebugUIDrawer.cs | 2 +- .../Editor/Debugging/DebugWindow.cs | 2 +- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/com.unity.render-pipelines.core/CHANGELOG.md b/com.unity.render-pipelines.core/CHANGELOG.md index b8e7c926f60..4d71867cd65 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Fixed XR support in CoreUtils.DrawFullscreen function. - Fixed issue in DynamicResolutionHandler when camera request was turned off at runtime, the ScalableBufferManager would leak state and not unset DRS state (case 1383093). +- Fixed undo in for `DebugUI.EnumFields` on the rendering debugger. (case 1386964) ## [13.1.2] - 2021-11-05 diff --git a/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs b/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs index 06d417e61c4..406fcccd1f7 100644 --- a/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs +++ b/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs @@ -134,11 +134,50 @@ public DebugStateAttribute(params Type[] types) [Serializable, DebugState(typeof(DebugUI.BoolField), typeof(DebugUI.Foldout), typeof(DebugUI.HistoryBoolField))] public sealed class DebugStateBool : DebugState { } + /// + /// Enums Debug State. + /// + [Serializable, DebugState(typeof(DebugUI.EnumField), typeof(DebugUI.HistoryEnumField))] + public sealed class DebugStateEnum : DebugState, ISerializationCallbackReceiver + { + DebugUI.EnumField m_EnumField; + + /// + /// Set the value of the Debug Item. + /// + /// Input value. + /// Debug Item field. + public override void SetValue(object value, DebugUI.IValueField field) + { + m_EnumField = field as DebugUI.EnumField; + this.value = (int)field.ValidateValue(value); + } + + void UpdateValue() + { + if (m_EnumField != null) + { + m_EnumField.SetValue(value); + m_EnumField.setIndex?.Invoke(value); + } + } + + /// + /// On Before Serialize Callback + /// + public void OnBeforeSerialize() => UpdateValue(); + + /// + /// On After Deserialize Callback + /// + public void OnAfterDeserialize() => UpdateValue(); + } + /// /// Integer Debug State. /// - [Serializable, DebugState(typeof(DebugUI.IntField), typeof(DebugUI.EnumField), typeof(DebugUI.HistoryEnumField))] - public sealed class DebugStateInt : DebugState { } + [Serializable, DebugState(typeof(DebugUI.IntField))] + public sealed class DebugStateInt : DebugState {} /// /// Flags Debug State. diff --git a/com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.Builtins.cs b/com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.Builtins.cs index 91f57d86d4b..f349ac746b4 100644 --- a/com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.Builtins.cs +++ b/com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.Builtins.cs @@ -304,7 +304,7 @@ public sealed class DebugUIDrawerEnumField : DebugUIDrawer public override bool OnGUI(DebugUI.Widget widget, DebugState state) { var w = Cast(widget); - var s = Cast(state); + var s = Cast(state); if (w.indexes == null) w.InitIndexes(); diff --git a/com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.cs b/com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.cs index 42bd940dc3d..3ce8b5fa531 100644 --- a/com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.cs +++ b/com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.cs @@ -81,7 +81,7 @@ public virtual void End(DebugUI.Widget widget, DebugState state) /// Input value. protected void Apply(DebugUI.IValueField widget, DebugState state, object value) { - Undo.RegisterCompleteObjectUndo(state, "Debug Property Change"); + Undo.RegisterCompleteObjectUndo(state, $"Debug Property '{state.queryPath}' Change"); state.SetValue(value, widget); widget.SetValue(value); EditorUtility.SetDirty(state); diff --git a/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs b/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs index 1b1d27dc5f8..d1a0e6a97d5 100644 --- a/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs +++ b/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs @@ -422,7 +422,7 @@ void OnGUI() GUI.Toggle(elementRect, m_Settings.selectedPanel == i, panel.displayName, s_Styles.sectionElement); if (EditorGUI.EndChangeCheck()) { - Undo.RegisterCompleteObjectUndo(m_Settings, "Debug Panel Selection"); + Undo.RegisterCompleteObjectUndo(m_Settings, $"Debug Panel '{panel.displayName}' Selection"); var previousPanel = m_Settings.selectedPanel >= 0 && m_Settings.selectedPanel < panels.Count ? panels[m_Settings.selectedPanel] : null; From 4754df1857305efa3711016e93d53c3f15208046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez?= Date: Mon, 10 Jan 2022 10:18:08 +0100 Subject: [PATCH 2/2] Format --- com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs b/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs index 406fcccd1f7..dbc0a4e7937 100644 --- a/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs +++ b/com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs @@ -177,7 +177,7 @@ void UpdateValue() /// Integer Debug State. /// [Serializable, DebugState(typeof(DebugUI.IntField))] - public sealed class DebugStateInt : DebugState {} + public sealed class DebugStateInt : DebugState { } /// /// Flags Debug State.