@@ -8,23 +8,32 @@ public abstract class CollectableIndirectReference
88 {
99 [ SerializeField ]
1010 protected string collectableGUID ;
11-
11+
1212 [ SerializeField ]
1313 protected string collectionGUID ;
14- }
15-
14+ }
15+
1616 [ Serializable ]
1717 public abstract class CollectableIndirectReference < TObject > : CollectableIndirectReference
1818 where TObject : CollectableScriptableObject
1919 {
2020 [ NonSerialized ]
2121 private TObject cachedRef ;
22+
23+ /// <summary>
24+ /// Alternative to [XmlIgnore] [JsonIgnore]
25+ /// </summary>
26+ /// <returns>false, because of a circular reference and the SO is not serializable</returns>
27+ public bool ShouldSerializeRef ( ) => false ;
28+
2229 public TObject Ref
2330 {
2431 get
2532 {
2633 if ( cachedRef != null )
34+ {
2735 return cachedRef ;
36+ }
2837
2938 if ( CollectionsRegistry . Instance . TryGetCollectionByGUID ( collectionGUID ,
3039 out ScriptableObjectCollection < TObject > collection ) )
@@ -38,6 +47,33 @@ public TObject Ref
3847
3948 return cachedRef ;
4049 }
50+ set => FromCollectable ( value ) ;
51+ }
52+
53+ /// <summary>
54+ /// Used for serializing, as the protected fields only work for Unity's serializer
55+ /// </summary>
56+ public string PairedGUID
57+ {
58+ get => collectionGUID + ":" + collectableGUID ;
59+ set
60+ {
61+ var split = value . Split ( ':' ) ;
62+ if ( split . Length == 2 )
63+ {
64+ collectionGUID = split [ 0 ] ;
65+ collectableGUID = split [ 1 ] ;
66+ }
67+ }
68+ }
69+
70+ public CollectableIndirectReference ( )
71+ {
72+ }
73+
74+ public CollectableIndirectReference ( TObject collectableScriptableObject )
75+ {
76+ FromCollectable ( collectableScriptableObject ) ;
4177 }
4278
4379 public void FromCollectable ( CollectableScriptableObject collectableScriptableObject )
0 commit comments