Skip to content

Commit bdcb755

Browse files
julienamsellemEvergreen
authored andcommitted
[VFX] Undoing slider value change not updating float field
1 parent 97e0eb0 commit bdcb755

4 files changed

Lines changed: 76 additions & 3 deletions

File tree

Packages/com.unity.visualeffectgraph/Editor/Controls/VFXSliderField.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public float ToScaled(float linearValue)
7676
}
7777
}
7878

79-
abstract class VFXBaseSliderField<T> : VisualElement, INotifyValueChanged<T>
79+
abstract class VFXBaseSliderField<T> : VisualElement, IVFXNotifyValueChanged<T>
8080
{
8181
protected readonly Slider m_Slider;
8282
protected readonly TextValueField<T> m_Field;
@@ -160,6 +160,11 @@ public void SetValueWithoutNotify(T newValue)
160160
SetValueWithoutNotify(ValueToFloat(newValue), newValue);
161161
}
162162

163+
public void SetValueWithoutNotify(T newValue, bool force)
164+
{
165+
SetValueWithoutNotify(ValueToFloat(newValue), newValue, force);
166+
}
167+
163168
public T value
164169
{
165170
get => m_Value;

Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/PropertyRM.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ interface IPropertyRMProvider
3636
void EndLiveModification();
3737
}
3838

39+
interface IVFXNotifyValueChanged<T> : INotifyValueChanged<T>
40+
{
41+
void SetValueWithoutNotify(T typedNewValue, bool force = false);
42+
}
3943

4044
class SimplePropertyRMProvider<T> : IPropertyRMProvider
4145
{
@@ -253,7 +257,7 @@ public void Update()
253257
Profiler.EndSample();
254258
Profiler.EndSample();
255259
}
256-
260+
257261
void UpdateExpandable()
258262
{
259263
if (IsExpandable())
@@ -617,7 +621,10 @@ public override void UpdateGUI(bool force)
617621
try
618622
{
619623
var value = (U)System.Convert.ChangeType(m_Value, typeof(U));
620-
m_Field.SetValueWithoutNotify(value);
624+
if (m_Field is IVFXNotifyValueChanged<U> vfxNotifyValueChanged)
625+
vfxNotifyValueChanged.SetValueWithoutNotify(value, force);
626+
else
627+
m_Field.SetValueWithoutNotify(value);
621628
}
622629
catch (System.Exception ex)
623630
{
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Collections;
2+
using System.Linq;
3+
4+
using NUnit.Framework;
5+
6+
using UnityEditor.VFX.Operator;
7+
using UnityEditor.VFX.UI;
8+
using UnityEngine.TestTools;
9+
using UnityEngine.UIElements;
10+
using UnityEngine.VFX;
11+
12+
namespace UnityEditor.VFX.Test
13+
{
14+
[TestFixture]
15+
public class PropertyRMTests
16+
{
17+
[UnityTest, Description("Covers UUM-92186")]
18+
public IEnumerator Undo_SliderChange()
19+
{
20+
// Arrange
21+
var graph = VFXTestCommon.MakeTemporaryGraph();
22+
var noiseOperator = (Noise)VFXLibrary.GetOperators().First(x => x.modelType == typeof(Noise)).CreateInstance();
23+
noiseOperator.GetInputSlot(3).value = 0f;
24+
graph.AddChild(noiseOperator);
25+
var path = AssetDatabase.GetAssetPath(graph);
26+
AssetDatabase.ImportAsset(path);
27+
28+
var asset = AssetDatabase.LoadAssetAtPath<VisualEffectAsset>(path);
29+
Assert.IsTrue(VisualEffectAssetEditor.OnOpenVFX(asset.GetInstanceID(), 0));
30+
var window = VFXViewWindow.GetWindow(asset, true);
31+
window.LoadAsset(asset, null);
32+
window.Show();
33+
yield return null;
34+
35+
// Find the Roughness slider UI
36+
var operatorUI = window.graphView.Q<VFXOperatorUI>();
37+
var roughnessSlider = operatorUI.Query<Slider>().Last();
38+
Assert.NotNull(roughnessSlider);
39+
var floatField = roughnessSlider.parent as FloatField;
40+
Assert.NotNull(floatField);
41+
42+
// Act
43+
Undo.IncrementCurrentGroup();
44+
floatField.Focus();
45+
roughnessSlider.value = 1f;
46+
yield return null;
47+
48+
Assert.AreEqual(1f, noiseOperator.GetInputSlot(3).value);
49+
Undo.PerformUndo();
50+
yield return null;
51+
52+
// Assert
53+
var value = (float)noiseOperator.GetInputSlot(3).value;
54+
Assert.AreEqual(0f, value);
55+
Assert.AreEqual(0f, floatField.value);
56+
}
57+
}
58+
}

Tests/SRPTests/Projects/VisualEffectGraph_HDRP/Assets/AllTests/Editor/Tests/PropertyRMTests.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)