Skip to content

Commit 48c2d7f

Browse files
committed
feat: Revert requireing old instance
1 parent ed97aa5 commit 48c2d7f

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Assets/JCSUnity/Scripts/Interfaces/JCS_Instance.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,22 @@ public abstract class JCS_InstanceOld<T> : JCS_Instance<T>
4040
/// <summary>
4141
/// Check singleton for keep the old one.
4242
/// </summary>
43-
/// <param name="_old"> old instance </param>
4443
/// <param name="_new"> new instance </param>
45-
protected void CheckInstance(T _old, T _new)
44+
/// <param name="destroyGO">
45+
/// If true, destory the entire game object instead of just the component.
46+
/// </param>
47+
protected void CheckInstance(T _new, bool destroyGO = false)
4648
{
4749
if (instance != null)
4850
{
4951
// only if needed
50-
TransferData(_old, _new);
52+
TransferData(instance, _new);
5153

5254
// Destory the new one; and keep the old one.
53-
Destroy(_new.gameObject);
55+
if (destroyGO)
56+
Destroy(_new.gameObject);
57+
else
58+
Destroy(_new);
5459

5560
return;
5661
}
@@ -88,17 +93,22 @@ public abstract class JCS_InstanceNew<T> : JCS_Instance<T>
8893
/// <summary>
8994
/// Check singleton for keep the new one.
9095
/// </summary>
91-
/// <param name="_old"> old instance </param>
9296
/// <param name="_new"> new instance </param>
93-
protected void CheckInstance(T _old, T _new)
97+
/// <param name="destroyGO">
98+
/// If true, destory the entire game object instead of just the component.
99+
/// </param>
100+
protected void CheckInstance(T _new, bool destroyGO = false)
94101
{
95102
if (instance != null)
96103
{
97104
// only if needed
98-
TransferData(_old, _new);
105+
TransferData(instance, _new);
99106

100107
// Destory the old one!
101-
Destroy(instance);
108+
if (destroyGO)
109+
Destroy(instance.gameObject);
110+
else
111+
Destroy(instance);
102112
}
103113

104114
// Assign the new one!

0 commit comments

Comments
 (0)