@@ -28,9 +28,55 @@ public static FieldInfo GetFieldInfoFromPathByType(this SerializedProperty prope
28
28
29
29
return fieldInfo ;
30
30
}
31
-
32
- public static void SetValue ( this SerializedProperty serializedProperty , object value )
31
+
32
+ public static void SetValueReflective ( this SerializedProperty prop , object value )
33
33
{
34
+ object root = prop . serializedObject . targetObject ;
35
+
36
+ string [ ] parts = prop . propertyPath
37
+ . Replace ( ".Array.data[" , "[" )
38
+ . Split ( '.' ) ;
39
+
40
+ object current = root ;
41
+ FieldInfo fi = null ;
42
+
43
+ for ( int i = 0 ; i < parts . Length ; i ++ )
44
+ {
45
+ string part = parts [ i ] ;
46
+
47
+ if ( part . EndsWith ( "]" ) )
48
+ {
49
+ int b = part . IndexOf ( '[' ) ;
50
+ string name = part . Substring ( 0 , b ) ;
51
+ int idx = int . Parse ( part . Substring ( b + 1 , part . Length - b - 2 ) ) ;
52
+
53
+ fi = current . GetType ( )
54
+ . GetField ( name ,
55
+ BindingFlags . Instance
56
+ | BindingFlags . NonPublic
57
+ | BindingFlags . Public ) ;
58
+ IList list = fi . GetValue ( current ) as System . Collections . IList ;
59
+ current = list [ idx ] ;
60
+ }
61
+ else
62
+ {
63
+ fi = current . GetType ( )
64
+ . GetField ( part ,
65
+ BindingFlags . Instance
66
+ | BindingFlags . NonPublic
67
+ | BindingFlags . Public ) ;
68
+ if ( i < parts . Length - 1 )
69
+ current = fi . GetValue ( current ) ;
70
+ }
71
+ }
72
+
73
+ fi . SetValue ( current , value ) ;
74
+
75
+ prop . serializedObject . Update ( ) ;
76
+ prop . serializedObject . ApplyModifiedProperties ( ) ;
77
+ }
78
+
79
+ public static void SetValue ( this SerializedProperty serializedProperty , object value ) {
34
80
switch ( serializedProperty . propertyType )
35
81
{
36
82
case SerializedPropertyType . Integer :
@@ -106,6 +152,12 @@ public static void SetValue(this SerializedProperty serializedProperty, object v
106
152
case SerializedPropertyType . Hash128 :
107
153
serializedProperty . hash128Value = ( Hash128 ) value ;
108
154
break ;
155
+ case SerializedPropertyType . ManagedReference :
156
+ serializedProperty . managedReferenceValue = value ;
157
+ break ;
158
+ case SerializedPropertyType . Generic :
159
+ serializedProperty . SetValueReflective ( value ) ;
160
+ break ;
109
161
default :
110
162
Debug . LogWarning (
111
163
$ "Tried to copy value '{ value } ' from a template to an SOC item but apparently that's not supported.") ;
0 commit comments