@@ -15,7 +15,6 @@ public sealed class CollectableIndirectReferenceDrawer : PropertyDrawer
1515 private SerializedProperty collectableGUIDProperty ;
1616 private SerializedProperty collectionGUIDProperty ;
1717
18- private CollectableScriptableObject collectableScriptableObject ;
1918 private CollectableScriptableObject cachedReference ;
2019
2120 public override void OnGUI ( Rect position , SerializedProperty property , GUIContent label )
@@ -24,24 +23,40 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
2423 collectableGUIDProperty = property . FindPropertyRelative ( COLLECTABLE_GUID_PROPERTY_PATH ) ;
2524 collectionGUIDProperty = property . FindPropertyRelative ( COLLECTION_GUID_PROPERTY_PATh ) ;
2625
27- if ( cachedReference == null
28- && ! string . IsNullOrEmpty ( collectableGUIDProperty . stringValue )
29- && ! string . IsNullOrEmpty ( collectionGUIDProperty . stringValue ) )
26+ if ( objectAssetProperty . objectReferenceValue != null )
3027 {
31- if ( CollectionsRegistry . Instance . TryGetCollectionByGUID ( collectionGUIDProperty . stringValue ,
32- out ScriptableObjectCollection collection ) )
28+ if ( string . IsNullOrEmpty ( collectableGUIDProperty . stringValue )
29+ || string . IsNullOrEmpty ( collectionGUIDProperty . stringValue ) )
3330 {
34- if ( collection . TryGetCollectableByGUID ( collectableGUIDProperty . stringValue ,
35- out CollectableScriptableObject collectable ) )
31+ CollectableScriptableObject collectable = objectAssetProperty . objectReferenceValue as CollectableScriptableObject ;
32+ collectableGUIDProperty . stringValue = collectable . GUID ;
33+ collectionGUIDProperty . stringValue = collectable . Collection . GUID ;
34+ objectAssetProperty . serializedObject . ApplyModifiedProperties ( ) ;
35+ }
36+ }
37+ else
38+ {
39+ if ( ! string . IsNullOrEmpty ( collectableGUIDProperty . stringValue )
40+ && ! string . IsNullOrEmpty ( collectionGUIDProperty . stringValue ) )
41+ {
42+ if ( CollectionsRegistry . Instance . TryGetCollectionByGUID ( collectionGUIDProperty . stringValue ,
43+ out ScriptableObjectCollection collection ) )
3644 {
37- cachedReference = collectable ;
45+ if ( collection . TryGetCollectableByGUID ( collectableGUIDProperty . stringValue ,
46+ out CollectableScriptableObject collectable ) )
47+ {
48+ objectAssetProperty . objectReferenceValue = collectable ;
49+ objectAssetProperty . serializedObject . ApplyModifiedProperties ( ) ;
50+ }
3851 }
3952 }
4053 }
41-
54+
55+ if ( cachedReference == null && objectAssetProperty . objectReferenceValue != null )
56+ cachedReference = objectAssetProperty . objectReferenceValue as CollectableScriptableObject ;
4257
4358 EditorGUI . PropertyField ( position , objectAssetProperty , label , true ) ;
44- if ( objectAssetProperty . exposedReferenceValue != cachedReference )
59+ if ( objectAssetProperty . objectReferenceValue != cachedReference )
4560 {
4661 string collectableGUID = string . Empty ;
4762 string collectionGUID = string . Empty ;
@@ -61,6 +76,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
6176 collectableGUIDProperty . stringValue = collectableGUID ;
6277 collectionGUIDProperty . stringValue = collectionGUID ;
6378 objectAssetProperty . serializedObject . ApplyModifiedProperties ( ) ;
79+ EditorUtility . SetDirty ( objectAssetProperty . serializedObject . targetObject ) ;
6480 }
6581 }
6682
0 commit comments