33using SLZ . Marrow . Warehouse ;
44using UltEvents ;
55using System . Reflection ;
6+ using UnityEditor ;
67
78namespace CustomCampaignTools . SDK
89{
@@ -17,26 +18,27 @@ void Reset()
1718 {
1819 CrateSpawner spawner = GetComponent < CrateSpawner > ( ) ;
1920 var call = spawner . onSpawnEvent . AddPersistentCall ( ( Action < CrateSpawner , GameObject > ) Setup ) ;
20- SetArgumentToParameter ( call . PersistentArguments [ 0 ] , 0 ) ;
21- SetArgumentToParameter ( call . PersistentArguments [ 1 ] , 1 ) ;
22- }
21+ SerializedObject serializedObject = new SerializedObject ( spawner ) ;
2322
24- private void SetArgumentToParameter ( PersistentArgument argument , int parameterIndex )
25- {
26- if ( argument == null ) return ;
23+ SerializedProperty persistentCallsProp = serializedObject . FindProperty ( "onSpawnEvent._PersistentCalls" ) ;
2724
28- // Find and set the "Mode" field to "Parameter"
29- FieldInfo modeField = typeof ( PersistentArgument ) . GetField ( nameof ( PersistentArgument . Type ) , BindingFlags . Instance | BindingFlags . NonPublic ) ;
30- if ( modeField != null )
25+ if ( persistentCallsProp . arraySize > 0 )
3126 {
32- modeField . SetValue ( argument , PersistentArgumentType . Parameter ) ;
33- }
27+ SerializedProperty lastCallProp = persistentCallsProp . GetArrayElementAtIndex ( persistentCallsProp . arraySize - 1 ) ;
28+ SerializedProperty argumentsProp = lastCallProp . FindPropertyRelative ( "PersistentArguments" ) ;
3429
35- // Set the ParameterIndex field
36- FieldInfo indexField = typeof ( PersistentArgument ) . GetField ( nameof ( PersistentArgument . ParameterIndex ) , BindingFlags . Instance | BindingFlags . Public ) ;
37- if ( indexField != null )
38- {
39- indexField . SetValue ( argument , parameterIndex ) ;
30+ if ( argumentsProp != null && argumentsProp . arraySize >= 2 )
31+ {
32+ // Modify arguments using SerializedProperties
33+ SerializedProperty firstArg = argumentsProp . GetArrayElementAtIndex ( 0 ) ;
34+ SerializedProperty secondArg = argumentsProp . GetArrayElementAtIndex ( 1 ) ;
35+
36+ firstArg . FindPropertyRelative ( "Type" ) . enumValueIndex = ( int ) PersistentArgumentType . Parameter ; // Parameter mode (likely index 2)
37+ firstArg . FindPropertyRelative ( "ParameterIndex" ) . intValue = 0 ;
38+
39+ secondArg . FindPropertyRelative ( "Type" ) . enumValueIndex = ( int ) PersistentArgumentType . Parameter ;
40+ secondArg . FindPropertyRelative ( "ParameterIndex" ) . intValue = 1 ;
41+ }
4042 }
4143 }
4244#endif
0 commit comments