@@ -916,6 +916,103 @@ bool CompareWithExpectedLog(StringBuilder actualContent, string identifier, out
916916 return success ;
917917 }
918918
919+ public static IEnumerable < IEnumerable < T > > PermutationHelper < T > ( IEnumerable < T > set , IEnumerable < T > subset = null )
920+ {
921+ if ( subset == null )
922+ subset = Enumerable . Empty < T > ( ) ;
923+
924+ if ( ! set . Any ( ) )
925+ yield return subset ;
926+
927+ for ( var i = 0 ; i < set . Count ( ) ; i ++ )
928+ {
929+ var newSubset = set . Take ( i ) . Concat ( set . Skip ( i + 1 ) ) ;
930+ foreach ( var permutation in PermutationHelper ( newSubset , subset . Concat ( set . Skip ( i ) . Take ( 1 ) ) ) )
931+ {
932+ yield return permutation ;
933+ }
934+ }
935+ }
936+
937+ public static string [ ] k_CreateSpawner_Chaining_And_Check_Expected_Ordering = PermutationHelper ( new [ ] { "A" , "B" , "C" , "D" } ) . Select ( o => o . Aggregate ( ( a , b ) => a + b ) ) . ToArray ( ) ;
938+ public static bool [ ] k_CreateSpawner_Chaining_And_Check_Expected_Plug_C_First = { true , false } ;
939+ [ UnityTest ]
940+ public IEnumerator CreateSpawner_Chaining_And_Check_Expected_Ordering ( [ ValueSource ( "k_CreateSpawner_Chaining_And_Check_Expected_Ordering" ) ] string ordering , [ ValueSource ( "k_CreateSpawner_Chaining_And_Check_Expected_Plug_C_First" ) ] bool plugCFirst )
941+ {
942+ var graph = VFXTestCommon . MakeTemporaryGraph ( ) ;
943+ // A -> B -> C -> Init
944+ // \-> D /
945+ var correctSequences = new string [ ] { "ABCD" , "ABDC" } ;
946+
947+ foreach ( var c in ordering )
948+ {
949+ var spawnerContext = ScriptableObject . CreateInstance < VFXBasicSpawner > ( ) ;
950+ var blockSpawnerConstant = ScriptableObject . CreateInstance < VFXSpawnerConstantRate > ( ) ;
951+ blockSpawnerConstant . GetInputSlot ( 0 ) . value = 0.1f ;
952+ spawnerContext . label = c . ToString ( ) ;
953+ spawnerContext . AddChild ( blockSpawnerConstant ) ;
954+ graph . AddChild ( spawnerContext ) ;
955+ }
956+
957+ var initialize = ScriptableObject . CreateInstance < VFXBasicInitialize > ( ) ;
958+ var setPosition = ScriptableObject . CreateInstance < SetAttribute > ( ) ;
959+ setPosition . SetSettingValue ( "attribute" , "position" ) ;
960+ initialize . AddChild ( setPosition ) ;
961+ var output = ScriptableObject . CreateInstance < VFXPointOutput > ( ) ;
962+ graph . AddChild ( initialize ) ;
963+ graph . AddChild ( output ) ;
964+ output . LinkFrom ( initialize ) ;
965+
966+ var spawn_a = graph . children . OfType < VFXBasicSpawner > ( ) . First ( o => o . label == "A" ) ;
967+ var spawn_b = graph . children . OfType < VFXBasicSpawner > ( ) . First ( o => o . label == "B" ) ;
968+ var spawn_c = graph . children . OfType < VFXBasicSpawner > ( ) . First ( o => o . label == "C" ) ;
969+ var spawn_d = graph . children . OfType < VFXBasicSpawner > ( ) . First ( o => o . label == "D" ) ;
970+
971+ if ( plugCFirst )
972+ {
973+ initialize . LinkFrom ( spawn_c ) ;
974+ initialize . LinkFrom ( spawn_d ) ;
975+ }
976+ else
977+ {
978+ initialize . LinkFrom ( spawn_d ) ;
979+ initialize . LinkFrom ( spawn_c ) ;
980+ }
981+
982+ spawn_d . LinkFrom ( spawn_a ) ;
983+ spawn_c . LinkFrom ( spawn_b ) ;
984+ spawn_b . LinkFrom ( spawn_a ) ;
985+
986+ Assert . AreEqual ( 2 , spawn_a . outputFlowSlot [ 0 ] . link . Count ) ;
987+ Assert . AreEqual ( 1 , spawn_b . outputFlowSlot [ 0 ] . link . Count ) ;
988+ Assert . AreEqual ( 1 , spawn_c . outputFlowSlot [ 0 ] . link . Count ) ;
989+ Assert . AreEqual ( 1 , spawn_d . outputFlowSlot [ 0 ] . link . Count ) ;
990+ graph . SetCompilationMode ( VFXCompilationMode . Runtime ) ;
991+ AssetDatabase . ImportAsset ( AssetDatabase . GetAssetPath ( graph ) ) ;
992+
993+ var gameObj = new GameObject ( "CreateSpawner_Chaining_And_Check_Expected_Ordering" ) ;
994+ var vfxComponent = gameObj . AddComponent < VisualEffect > ( ) ;
995+ vfxComponent . visualEffectAsset = graph . visualEffectResource . asset ;
996+
997+ var particleSystem = new List < string > ( ) ;
998+ vfxComponent . GetParticleSystemNames ( particleSystem ) ;
999+ Assert . AreEqual ( 1 , particleSystem . Count ) ;
1000+
1001+ var spawnSystem = new List < string > ( ) ;
1002+ vfxComponent . GetSpawnSystemNames ( spawnSystem ) ;
1003+ Assert . AreEqual ( 4 , spawnSystem . Count ) ;
1004+ Assert . Contains ( "A" , spawnSystem ) ;
1005+ Assert . Contains ( "B" , spawnSystem ) ;
1006+ Assert . Contains ( "C" , spawnSystem ) ;
1007+ Assert . Contains ( "D" , spawnSystem ) ;
1008+
1009+ var actualSequence = spawnSystem . Aggregate ( ( a , b ) => a + b ) ;
1010+ Assert . Contains ( actualSequence , correctSequences ) ;
1011+ yield return null ;
1012+
1013+ GameObject . DestroyImmediate ( gameObj ) ;
1014+ }
1015+
9191016 static readonly System . Reflection . MethodInfo [ ] k_SpawnerStateGetter = typeof ( VFXSpawnerState ) . GetMethods ( ) . Where ( o => o . Name . StartsWith ( "get_" ) && o . Name != "get_vfxEventAttribute" ) . ToArray ( ) ;
9201017 static string DebugSpawnerStateAggregate ( IEnumerable < string > all )
9211018 {
0 commit comments