From 40307dc926a88916e7f850623a92224cc6032d3f Mon Sep 17 00:00:00 2001 From: Paul Demeulenaere Date: Fri, 3 Jul 2020 18:15:06 +0200 Subject: [PATCH 1/3] Add AssetEditor from https://github.cds.internal.unity3d.com/unity/vfx-graphics/pull/4 --- .../Editor/Inspector/VFXAssetEditor.cs | 97 ++++++++++++++++++- 1 file changed, 93 insertions(+), 4 deletions(-) diff --git a/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs b/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs index feae7c6a1d8..63919a1db63 100644 --- a/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs +++ b/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs @@ -414,13 +414,102 @@ public override void OnInspectorGUI() GUI.enabled = AssetDatabase.IsOpenForEdit(this.target, StatusQueryOptions.UseCachedIfPossible); + VFXUpdateMode initialUpdateMode = (VFXUpdateMode)0; + bool? initialFixedDeltaTime = null; + bool? initialProcessEveryFrame = null; + bool? initialIgnoreGameTimeScale = null; + if (resourceUpdateModeProperty.hasMultipleDifferentValues) + { + var resourceUpdateModeProperties = resourceUpdateModeProperty.serializedObject.targetObjects + .Select(o => new SerializedObject(o) + .FindProperty(resourceUpdateModeProperty.propertyPath)) + .ToArray(); //N.B.: This will create garbage + var allDeltaTime = resourceUpdateModeProperties.Select(o => ((VFXUpdateMode)o.intValue & VFXUpdateMode.DeltaTime) == VFXUpdateMode.DeltaTime) + .Distinct(); + var allProcessEveryFrame = resourceUpdateModeProperties.Select(o => ((VFXUpdateMode)o.intValue & VFXUpdateMode.ExactFixedTimeStep) == VFXUpdateMode.ExactFixedTimeStep) + .Distinct(); + var allIgnoreScale = resourceUpdateModeProperties.Select(o => ((VFXUpdateMode)o.intValue & VFXUpdateMode.IgnoreTimeScale) == VFXUpdateMode.IgnoreTimeScale) + .Distinct(); + if (allDeltaTime.Count() == 1) + initialFixedDeltaTime = !allDeltaTime.First(); + if (allProcessEveryFrame.Count() == 1) + initialProcessEveryFrame = allProcessEveryFrame.First(); + if (allIgnoreScale.Count() == 1) + initialIgnoreGameTimeScale = allIgnoreScale.First(); + } + else + { + initialUpdateMode = (VFXUpdateMode)resourceUpdateModeProperty.intValue; + initialFixedDeltaTime = !((initialUpdateMode & VFXUpdateMode.DeltaTime) == VFXUpdateMode.DeltaTime); + initialProcessEveryFrame = (initialUpdateMode & VFXUpdateMode.ExactFixedTimeStep) == VFXUpdateMode.ExactFixedTimeStep; + initialIgnoreGameTimeScale = (initialUpdateMode & VFXUpdateMode.IgnoreTimeScale) == VFXUpdateMode.IgnoreTimeScale; + } + + EditorGUI.showMixedValue = !initialFixedDeltaTime.HasValue; + var deltaTimeContent = EditorGUIUtility.TrTextContent("Fixed Delta Time", "If enabled, use visual effect manager fixed delta time mode."); + var processEveryFrameContent = EditorGUIUtility.TrTextContent("Exact Fixed Time", "Only relevant for fixed delta time mode, if enabled, can process several updates per frame (e.g.: if a frame is 30ms but the fixed frame rate is set to 5ms, it will update 6 times with a 5ms deltaTime instead of one time with a 30ms deltaTime). This update mode isn't efficient and should only be used for really high quality purpose."); + var ignoreTimeScaleContent = EditorGUIUtility.TrTextContent("Ignore Time Scale", "If enabled, the computed visual effect delta time ignore the game time scale value (play rate is still applied)."); + EditorGUI.BeginChangeCheck(); - EditorGUI.showMixedValue = resourceUpdateModeProperty.hasMultipleDifferentValues; - VFXUpdateMode newUpdateMode = (VFXUpdateMode)EditorGUILayout.EnumPopup(EditorGUIUtility.TrTextContent("Update Mode", "Specifies whether particles are updated using a fixed timestep (Fixed Delta Time), or in a frame-rate independent manner (Delta Time)."), (VFXUpdateMode)resourceUpdateModeProperty.intValue); + + VisualEffectEditor.ShowHeader(EditorGUIUtility.TrTextContent("Update mode"), false, false); + bool newFixedDeltaTime = EditorGUILayout.Toggle(deltaTimeContent, initialFixedDeltaTime ?? false); + bool newExactFixedTimeStep = false; + EditorGUI.showMixedValue = !initialProcessEveryFrame.HasValue; + if (initialFixedDeltaTime.HasValue && initialFixedDeltaTime.Value || resourceUpdateModeProperty.hasMultipleDifferentValues) + newExactFixedTimeStep = EditorGUILayout.Toggle(processEveryFrameContent, initialProcessEveryFrame ?? false); + EditorGUI.showMixedValue = !initialIgnoreGameTimeScale.HasValue; + bool newIgnoreTimeScale = EditorGUILayout.Toggle(ignoreTimeScaleContent, initialIgnoreGameTimeScale ?? false); + if (EditorGUI.EndChangeCheck()) { - resourceUpdateModeProperty.intValue = (int)newUpdateMode; - resourceObject.ApplyModifiedProperties(); + if (!resourceUpdateModeProperty.hasMultipleDifferentValues) + { + var newUpdateMode = (VFXUpdateMode)0; + if (!newFixedDeltaTime) + newUpdateMode = newUpdateMode | VFXUpdateMode.DeltaTime; + if (newExactFixedTimeStep) + newUpdateMode = newUpdateMode | VFXUpdateMode.ExactFixedTimeStep; + if (newIgnoreTimeScale) + newUpdateMode = newUpdateMode | VFXUpdateMode.IgnoreTimeScale; + + resourceUpdateModeProperty.intValue = (int)newUpdateMode; + resourceObject.ApplyModifiedProperties(); + } + else + { + var resourceUpdateModeProperties = resourceUpdateModeProperty.serializedObject.targetObjects.Select(o => new SerializedObject(o).FindProperty(resourceUpdateModeProperty.propertyPath)); + foreach (var property in resourceUpdateModeProperties) + { + var updateMode = (VFXUpdateMode)property.intValue; + + if (initialFixedDeltaTime.HasValue) + { + if (!newFixedDeltaTime) + updateMode = updateMode | VFXUpdateMode.DeltaTime; + else + updateMode = updateMode & ~VFXUpdateMode.DeltaTime; + } + else + { + if (newFixedDeltaTime) + updateMode = updateMode & ~VFXUpdateMode.DeltaTime; + } + + if (newExactFixedTimeStep) + updateMode = updateMode | VFXUpdateMode.ExactFixedTimeStep; + else if (initialProcessEveryFrame.HasValue) + updateMode = updateMode & ~VFXUpdateMode.ExactFixedTimeStep; + + if (newIgnoreTimeScale) + updateMode = updateMode | VFXUpdateMode.IgnoreTimeScale; + else if (initialIgnoreGameTimeScale.HasValue) + updateMode = updateMode & ~VFXUpdateMode.IgnoreTimeScale; + + property.intValue = (int)updateMode; + property.serializedObject.ApplyModifiedProperties(); + } + } } EditorGUILayout.BeginHorizontal(); From 8d0dec71064e1db91247b1e6bd512525fd6532e2 Mon Sep 17 00:00:00 2001 From: Paul Demeulenaere Date: Fri, 3 Jul 2020 18:27:21 +0200 Subject: [PATCH 2/3] *Update changelog.md --- com.unity.visualeffectgraph/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.visualeffectgraph/CHANGELOG.md b/com.unity.visualeffectgraph/CHANGELOG.md index 9b2be6a1819..a4f903be886 100644 --- a/com.unity.visualeffectgraph/CHANGELOG.md +++ b/com.unity.visualeffectgraph/CHANGELOG.md @@ -25,6 +25,7 @@ The version number for this package has increased due to a version update of a r - Fix space issues with blocks and operators taking a camera as input - Generated shaderName are now consistent with displayed system names - Don't lose SRP output specific data when SRP package is not present +- Add cleaner Update Mode inspector [Case 1258463](https://issuetracker.unity3d.com/product/unity/issues/guid/1258463/) ## [8.0.1] - 2020-02-25 From 3fd82876b4cec0df60699bf0b6d229a73ffe3fad Mon Sep 17 00:00:00 2001 From: Paul Demeulenaere Date: Fri, 18 Sep 2020 15:58:13 +0200 Subject: [PATCH 3/3] Fix serveral minor issues Fix issue https://github.com/Unity-Technologies/Graphics/pull/1131#discussion_r458987790 Fix issue https://github.com/Unity-Technologies/Graphics/pull/1131#discussion_r458988272 Fix issue https://github.com/Unity-Technologies/Graphics/pull/1131#discussion_r458988870 --- .../Editor/Inspector/VFXAssetEditor.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs b/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs index 63919a1db63..ef88f45fd0b 100644 --- a/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs +++ b/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs @@ -446,9 +446,9 @@ public override void OnInspectorGUI() } EditorGUI.showMixedValue = !initialFixedDeltaTime.HasValue; - var deltaTimeContent = EditorGUIUtility.TrTextContent("Fixed Delta Time", "If enabled, use visual effect manager fixed delta time mode."); - var processEveryFrameContent = EditorGUIUtility.TrTextContent("Exact Fixed Time", "Only relevant for fixed delta time mode, if enabled, can process several updates per frame (e.g.: if a frame is 30ms but the fixed frame rate is set to 5ms, it will update 6 times with a 5ms deltaTime instead of one time with a 30ms deltaTime). This update mode isn't efficient and should only be used for really high quality purpose."); - var ignoreTimeScaleContent = EditorGUIUtility.TrTextContent("Ignore Time Scale", "If enabled, the computed visual effect delta time ignore the game time scale value (play rate is still applied)."); + var deltaTimeContent = EditorGUIUtility.TrTextContent("Fixed Delta Time", "If enabled, use visual effect manager fixed delta time mode, otherwise, use the default Time.deltaTime."); + var processEveryFrameContent = EditorGUIUtility.TrTextContent("Exact Fixed Time", "Only relevant when using Fixed Delta Time. When enabled, several updates can be processed per frame (e.g.: if a frame is 10ms and the fixed frame rate is set to 5 ms, the effect will update twice with a 5ms deltaTime instead of once with a 10ms deltaTime). This method is expensive and should only be used for high-end scenarios."); + var ignoreTimeScaleContent = EditorGUIUtility.TrTextContent("Ignore Time Scale", "When enabled, the computed visual effect delta time ignores the game Time Scale value (Play Rate is still applied)."); EditorGUI.BeginChangeCheck(); @@ -456,8 +456,9 @@ public override void OnInspectorGUI() bool newFixedDeltaTime = EditorGUILayout.Toggle(deltaTimeContent, initialFixedDeltaTime ?? false); bool newExactFixedTimeStep = false; EditorGUI.showMixedValue = !initialProcessEveryFrame.HasValue; - if (initialFixedDeltaTime.HasValue && initialFixedDeltaTime.Value || resourceUpdateModeProperty.hasMultipleDifferentValues) - newExactFixedTimeStep = EditorGUILayout.Toggle(processEveryFrameContent, initialProcessEveryFrame ?? false); + EditorGUI.BeginDisabledGroup((!initialFixedDeltaTime.HasValue || !initialFixedDeltaTime.Value) && !resourceUpdateModeProperty.hasMultipleDifferentValues); + newExactFixedTimeStep = EditorGUILayout.Toggle(processEveryFrameContent, initialProcessEveryFrame ?? false); + EditorGUI.EndDisabledGroup(); EditorGUI.showMixedValue = !initialIgnoreGameTimeScale.HasValue; bool newIgnoreTimeScale = EditorGUILayout.Toggle(ignoreTimeScaleContent, initialIgnoreGameTimeScale ?? false);