Skip to content

Commit 7ae1939

Browse files
PaulDemeulenaereGitHub Enterprise
authored andcommitted
1 parent 66aa776 commit 7ae1939

File tree

6 files changed

+113
-3
lines changed

6 files changed

+113
-3
lines changed

TestProjects/VisualEffectGraph/Assets/AllTests/Editor/Tests/VFXCustomSpawnerSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using UnityEngine;
33
using UnityEngine.VFX;
44

5-
namespace UnityEditor.VFX
5+
namespace UnityEditor.VFX.Test
66
{
77
class VFXCustomSpawnerSample : VFXSpawnerCallbacks
88
{

TestProjects/VisualEffectGraph/Assets/AllTests/Editor/Tests/VFXCustomSpawnerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using UnityEngine;
33
using UnityEngine.VFX;
44

5-
namespace UnityEditor.VFX
5+
namespace UnityEditor.VFX.Test
66
{
77
class VFXCustomSpawnerTest : VFXSpawnerCallbacks
88
{
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using UnityEngine;
3+
using UnityEngine.VFX;
4+
5+
namespace UnityEditor.VFX.Test
6+
{
7+
class VFXCustomSpawnerTimeCheckerTest : VFXSpawnerCallbacks
8+
{
9+
static public float s_ReadTotalTimeThroughInput = -571.0f;
10+
static public float s_ReadInternalTotalTime = -27.0f;
11+
12+
public class InputProperties
13+
{
14+
public float totalTime = 86;
15+
}
16+
17+
public override void OnPlay(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
18+
{
19+
}
20+
21+
22+
static private int s_totalTimeID = Shader.PropertyToID("totalTime");
23+
public override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
24+
{
25+
s_ReadTotalTimeThroughInput = vfxValues.GetFloat(s_totalTimeID);
26+
s_ReadInternalTotalTime = state.totalTime;
27+
}
28+
29+
public override void OnStop(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
30+
{
31+
}
32+
}
33+
}

TestProjects/VisualEffectGraph/Assets/AllTests/Editor/Tests/VFXCustomSpawnerTimeCheckerTest.cs.meta

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

TestProjects/VisualEffectGraph/Assets/AllTests/Editor/Tests/VFXCustomSpawnerUpdateCounterTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using UnityEngine;
33
using UnityEngine.VFX;
44

5-
namespace UnityEditor.VFX
5+
namespace UnityEditor.VFX.Test
66
{
77
class VFXCustomSpawnerUpdateCounterTest : VFXSpawnerCallbacks
88
{

TestProjects/VisualEffectGraph/Assets/AllTests/Editor/Tests/VFXDebugExpressionTest.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,72 @@ public IEnumerator Create_Asset_And_Component_Check_Expected_TotalTime()
100100
yield return new ExitPlayMode();
101101
}
102102

103+
[UnityTest]
104+
public IEnumerator Check_Total_Time_Is_Always_The_Sum_of_DeltaTime()
105+
{
106+
yield return new EnterPlayMode();
107+
var graph = VFXTestCommon.MakeTemporaryGraph();
108+
109+
var spawnerContext = ScriptableObject.CreateInstance<VFXBasicSpawner>();
110+
111+
var blockCustomSpawner = ScriptableObject.CreateInstance<VFXSpawnerCustomWrapper>();
112+
blockCustomSpawner.SetSettingValue("m_customType", new SerializableType(typeof(VFXCustomSpawnerTimeCheckerTest)));
113+
114+
var initContext = ScriptableObject.CreateInstance<VFXBasicInitialize>();
115+
var outputContext = ScriptableObject.CreateInstance<VFXPointOutput>();
116+
117+
spawnerContext.LinkTo(initContext);
118+
initContext.LinkTo(outputContext);
119+
120+
spawnerContext.AddChild(blockCustomSpawner);
121+
graph.AddChild(spawnerContext);
122+
graph.AddChild(initContext);
123+
graph.AddChild(outputContext);
124+
125+
//plug total time into custom spawn total time
126+
var builtInParameter = ScriptableObject.CreateInstance<VFXBuiltInParameter>();
127+
builtInParameter.SetSettingValue("m_expressionOp", VFXExpressionOperation.TotalTime);
128+
blockCustomSpawner.inputSlots[0].Link(builtInParameter.outputSlots[0]);
129+
130+
graph.AddChild(builtInParameter);
131+
132+
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph));
133+
134+
var vfxComponent = m_gameObject.AddComponent<VisualEffect>();
135+
vfxComponent.visualEffectAsset = graph.visualEffectResource.asset;
136+
137+
int maxFrame = 64;
138+
while (vfxComponent.culled && --maxFrame > 0)
139+
yield return null;
140+
Assert.IsTrue(maxFrame > 0);
141+
142+
while (--maxFrame > 0 && VFXCustomSpawnerTimeCheckerTest.s_ReadInternalTotalTime < 0.2f)
143+
yield return null;
144+
Assert.IsTrue(maxFrame > 0);
145+
146+
//Moved the object until culled
147+
var backupPosition = vfxComponent.transform.position;
148+
149+
maxFrame = 64;
150+
while (--maxFrame > 0 && !vfxComponent.culled)
151+
{
152+
vfxComponent.transform.position = vfxComponent.transform.position + Vector3.up * 5.0f;
153+
yield return null;
154+
}
155+
Assert.IsTrue(maxFrame > 0);
156+
157+
for (int i = 0; i < 8; ++i)
158+
yield return null;
159+
160+
vfxComponent.transform.position = backupPosition;
161+
162+
for (int i = 0; i < 8; ++i)
163+
yield return null;
164+
165+
Assert.AreEqual((double)VFXCustomSpawnerTimeCheckerTest.s_ReadInternalTotalTime, (double)VFXCustomSpawnerTimeCheckerTest.s_ReadTotalTimeThroughInput, 0.0001f);
166+
yield return new ExitPlayMode();
167+
}
168+
103169
#pragma warning disable 0414
104170
public static object[] updateModes = { VFXUpdateMode.FixedDeltaTime, VFXUpdateMode.DeltaTime };
105171
#pragma warning restore 0414

0 commit comments

Comments
 (0)