com.wallstop-studios.unity-helpers 1.0.1-rc10 → 1.0.1-rc11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
namespace UnityHelpers.Utils
|
|
2
2
|
{
|
|
3
|
+
using System;
|
|
3
4
|
using UnityEngine;
|
|
4
5
|
|
|
5
6
|
[DisallowMultipleComponent]
|
|
6
7
|
public abstract class RuntimeSingleton<T> : MonoBehaviour where T : RuntimeSingleton<T>
|
|
7
8
|
{
|
|
8
|
-
|
|
9
|
+
protected static T _instance;
|
|
9
10
|
|
|
10
11
|
protected virtual bool Preserve => true;
|
|
11
12
|
|
|
@@ -18,7 +19,8 @@
|
|
|
18
19
|
return _instance;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
Type type = typeof(T);
|
|
23
|
+
GameObject instance = new($"{type.Name}-Singleton", type);
|
|
22
24
|
if (instance.TryGetComponent(out _instance) && _instance.Preserve)
|
|
23
25
|
{
|
|
24
26
|
DontDestroyOnLoad(instance);
|