Skip to content

Commit f56fc38

Browse files
committed
Add Constructor to create a IndirectReference from a Collection Item, requires updating generated code
1 parent 8e26daf commit f56fc38

3 files changed

Lines changed: 24 additions & 9 deletions

File tree

Scripts/Editor/CreateCollectionWizzard.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ private void CreateIndirectAccess()
264264
CodeGenerationUtility.AppendLine(writer, 0,
265265
$"#endif");
266266

267+
CodeGenerationUtility.AppendLine(writer, indentation,
268+
$"public {collectableName}IndirectReference() {{}}");
269+
270+
CodeGenerationUtility.AppendLine(writer, indentation,
271+
$"public {collectableName}IndirectReference({collectableName} collectableScriptableObject) : base(collectableScriptableObject) {{}}");
272+
267273
indentation--;
268274
CodeGenerationUtility.AppendFooter(writer, ref indentation, TargetNameSpace);
269275
}

Scripts/Runtime/CollectableIndirectReference.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public abstract class CollectableIndirectReference
1111

1212
[SerializeField]
1313
protected string collectionGUID;
14-
}
15-
14+
}
15+
1616
[Serializable]
1717
public abstract class CollectableIndirectReference<TObject> : CollectableIndirectReference
1818
where TObject : CollectableScriptableObject
@@ -38,6 +38,16 @@ public TObject Ref
3838

3939
return cachedRef;
4040
}
41+
set => FromCollectable(value);
42+
}
43+
44+
public CollectableIndirectReference()
45+
{
46+
}
47+
48+
public CollectableIndirectReference(TObject collectableScriptableObject)
49+
{
50+
FromCollectable(collectableScriptableObject);
4151
}
4252

4353
public void FromCollectable(CollectableScriptableObject collectableScriptableObject)

Scripts/Runtime/CollectableScriptableObject.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public string GUID
1919
[SerializeField, HideInInspector]
2020
private ScriptableObjectCollection collection;
2121
public ScriptableObjectCollection Collection => collection;
22-
22+
2323
public void SetCollection(ScriptableObjectCollection collection)
2424
{
2525
this.collection = collection;
@@ -40,7 +40,7 @@ public override bool Equals(object o)
4040
return ReferenceEquals(this, other);
4141
}
4242

43-
public static bool operator==(CollectableScriptableObject left, CollectableScriptableObject right)
43+
public static bool operator ==(CollectableScriptableObject left, CollectableScriptableObject right)
4444
{
4545
if (ReferenceEquals(left, right))
4646
return true;
@@ -61,9 +61,9 @@ public override bool Equals(object o)
6161

6262
private void SyncGUID()
6363
{
64-
if (!string.IsNullOrEmpty(guid))
64+
if (!string.IsNullOrEmpty(guid))
6565
return;
66-
66+
6767
guid = Guid.NewGuid().ToString();
6868
#if UNITY_EDITOR
6969
string assetPath = UnityEditor.AssetDatabase.GetAssetPath(this);
@@ -73,9 +73,8 @@ private void SyncGUID()
7373
ObjectUtility.SetDirty(this);
7474
}
7575
#endif
76-
7776
}
78-
77+
7978
public override int GetHashCode()
8079
{
8180
return GUID.GetHashCode();
@@ -92,4 +91,4 @@ public void GenerateNewGUID()
9291
SyncGUID();
9392
}
9493
}
95-
}
94+
}

0 commit comments

Comments
 (0)