@@ -10,17 +10,11 @@ namespace TNRD
1010 [ CustomPropertyDrawer ( typeof ( SerializableInterface < > ) , true ) ]
1111 internal sealed class SerializableInterfacePropertyDrawer : PropertyDrawer
1212 {
13- private const string RAW_REFERENCE = "rawReference" ;
14- private const string MODE = "mode" ;
15-
1613 private SerializedProperty serializedProperty ;
1714 private Type genericType ;
1815
1916 private IReferenceDrawer activeDrawer ;
2017
21- private object previousReferenceValue ;
22- private string previousPropertyPath ;
23-
2418 /// <inheritdoc />
2519 public override bool CanCacheInspectorGUI ( SerializedProperty property ) => false ;
2620
@@ -48,48 +42,8 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent
4842 public override void OnGUI ( Rect position , SerializedProperty property , GUIContent label )
4943 {
5044 Initialize ( property ) ;
51- AvoidDuplicateReferencesInArray ( property ) ;
52-
5345 activeDrawer = GetReferenceDrawer ( activeDrawer , property , label ) ;
5446 activeDrawer . OnGUI ( position ) ;
55- previousPropertyPath = property . propertyPath ;
56- }
57-
58- /// <summary>
59- /// When a new instance of <see cref="SerializableInterface{T}"/> is added in an array using the inspector's gizmo,
60- /// avoids having their <see cref="SerializableInterface{T}.rawReference"/> field reference the same instance.
61- /// </summary>
62- /// <param name="property">The SerializedProperty to make the custom GUI for.</param>
63- private void AvoidDuplicateReferencesInArray ( SerializedProperty property )
64- {
65- if ( ! IsPropertyInArray ( property ) ) return ;
66- if ( previousPropertyPath == null ) return ;
67- if ( previousPropertyPath == property . propertyPath ) return ;
68-
69- var rawReferenceProperty = property . FindPropertyRelative ( RAW_REFERENCE ) ;
70- var currentReferenceValue = rawReferenceProperty . managedReferenceValue ;
71-
72- if ( currentReferenceValue == null ) return ;
73-
74- if ( previousReferenceValue == currentReferenceValue )
75- {
76- rawReferenceProperty . managedReferenceValue = CreateInstance ( currentReferenceValue ) ;
77- rawReferenceProperty . serializedObject . ApplyModifiedProperties ( ) ;
78- }
79-
80- previousReferenceValue = currentReferenceValue ;
81- }
82-
83- private static bool IsPropertyInArray ( SerializedProperty prop )
84- {
85- return prop . propertyPath . Contains ( ".Array.data[" ) ;
86- }
87-
88- private static object CreateInstance ( object source )
89- {
90- var instance = Activator . CreateInstance ( source . GetType ( ) ) ;
91- EditorUtility . CopySerializedManagedFieldsOnly ( source , instance ) ;
92- return instance ;
9347 }
9448
9549 private Type GetGenericArgument ( )
@@ -134,7 +88,7 @@ private IReferenceDrawer GetReferenceDrawer(
13488 GUIContent label
13589 )
13690 {
137- SerializedProperty modeProperty = serializedProperty . FindPropertyRelative ( MODE ) ;
91+ SerializedProperty modeProperty = serializedProperty . FindPropertyRelative ( "mode" ) ;
13892 ReferenceMode referenceMode = ( ReferenceMode ) modeProperty . enumValueIndex ;
13993
14094 switch ( referenceMode )
0 commit comments