Skip to content

Commit a596ef0

Browse files
gabrieldelacruzEvergreen
authored andcommitted
[VFX] Improve editing prewarm values for visual effect asset
1 parent 5749b28 commit a596ef0

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

Packages/com.unity.visualeffectgraph/Editor/Inspector/VFXAssetEditor.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -544,15 +544,16 @@ public static void DisplayPrewarmInspectorGUI(SerializedObject resourceObject, S
544544
if (!prewarmDeltaTime.hasMultipleDifferentValues && !prewarmStepCount.hasMultipleDifferentValues)
545545
{
546546
var currentDeltaTime = prewarmDeltaTime.floatValue;
547-
var currentStepCount = prewarmStepCount.uintValue;
547+
int currentStepCount = (int)prewarmStepCount.uintValue;
548548
var currentTotalTime = currentDeltaTime * currentStepCount;
549549
EditorGUI.BeginChangeCheck();
550550
currentTotalTime = EditorGUILayout.FloatField(EditorGUIUtility.TrTextContent("PreWarm Total Time", "Sets the time in seconds to advance the current effect to when it is initially played. "), currentTotalTime);
551551
if (EditorGUI.EndChangeCheck())
552552
{
553-
if (currentStepCount <= 0)
553+
if (currentStepCount <= 0 && currentTotalTime != 0.0f)
554554
{
555-
prewarmStepCount.uintValue = currentStepCount = 1u;
555+
currentStepCount = 1;
556+
prewarmStepCount.uintValue = (uint)currentStepCount;
556557
}
557558

558559
currentDeltaTime = currentTotalTime / currentStepCount;
@@ -561,17 +562,18 @@ public static void DisplayPrewarmInspectorGUI(SerializedObject resourceObject, S
561562
}
562563

563564
EditorGUI.BeginChangeCheck();
564-
currentStepCount = (uint)EditorGUILayout.IntField(EditorGUIUtility.TrTextContent("PreWarm Step Count", "Sets the number of simulation steps the prewarm should be broken down to. "), (int)currentStepCount);
565+
currentStepCount = EditorGUILayout.IntField(EditorGUIUtility.TrTextContent("PreWarm Step Count", "Sets the number of simulation steps the prewarm should be broken down to. "), (int)currentStepCount);
565566
if (EditorGUI.EndChangeCheck())
566567
{
567-
if (currentStepCount <= 0 && currentTotalTime != 0.0f)
568+
bool hasPrewarm = currentTotalTime != 0.0f;
569+
if (currentStepCount <= 0)
568570
{
569-
prewarmStepCount.uintValue = currentStepCount = 1;
571+
currentStepCount = hasPrewarm ? 1 : 0;
570572
}
571573

572-
currentDeltaTime = currentTotalTime == 0.0f ? 0.0f : currentTotalTime / currentStepCount;
574+
currentDeltaTime = hasPrewarm ? currentTotalTime / currentStepCount : 0.0f;
573575
prewarmDeltaTime.floatValue = currentDeltaTime;
574-
prewarmStepCount.uintValue = currentStepCount;
576+
prewarmStepCount.uintValue = (uint)currentStepCount;
575577
resourceObject.ApplyModifiedProperties();
576578
}
577579

@@ -581,18 +583,18 @@ public static void DisplayPrewarmInspectorGUI(SerializedObject resourceObject, S
581583
{
582584
if (currentDeltaTime < k_MinimalCommonDeltaTime)
583585
{
584-
prewarmDeltaTime.floatValue = currentDeltaTime = k_MinimalCommonDeltaTime;
586+
currentDeltaTime = k_MinimalCommonDeltaTime;
585587
}
586588

587-
if (currentDeltaTime > currentTotalTime)
589+
float totalTime = currentDeltaTime * currentStepCount;
590+
if (totalTime > currentTotalTime)
588591
{
589-
currentTotalTime = currentDeltaTime;
592+
currentTotalTime = totalTime;
590593
}
591-
592-
if (currentTotalTime != 0.0f)
594+
else
593595
{
594-
var candidateStepCount_A = (uint)Mathf.FloorToInt(currentTotalTime / currentDeltaTime);
595-
var candidateStepCount_B = (uint)Mathf.RoundToInt(currentTotalTime / currentDeltaTime);
596+
var candidateStepCount_A = Mathf.FloorToInt(currentTotalTime / currentDeltaTime);
597+
var candidateStepCount_B = Mathf.RoundToInt(currentTotalTime / currentDeltaTime);
596598

597599
var totalTime_A = currentDeltaTime * candidateStepCount_A;
598600
var totalTime_B = currentDeltaTime * candidateStepCount_B;
@@ -606,7 +608,7 @@ public static void DisplayPrewarmInspectorGUI(SerializedObject resourceObject, S
606608
currentStepCount = candidateStepCount_B;
607609
}
608610

609-
prewarmStepCount.uintValue = currentStepCount;
611+
prewarmStepCount.uintValue = (uint)currentStepCount;
610612
}
611613
prewarmDeltaTime.floatValue = currentDeltaTime;
612614
resourceObject.ApplyModifiedProperties();

0 commit comments

Comments
 (0)