com.wallstop-studios.unity-helpers 2.0.0-rc08 → 2.0.0-rc09

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,15 +1,18 @@
1
1
  namespace UnityHelpers.Utils
2
2
  {
3
3
  using System;
4
+ using Core.Extension;
5
+ using Core.Helper;
4
6
  using UnityEngine;
5
7
 
6
8
  [DisallowMultipleComponent]
7
- public abstract class RuntimeSingleton<T> : MonoBehaviour where T : RuntimeSingleton<T>
9
+ public abstract class RuntimeSingleton<T> : MonoBehaviour
10
+ where T : RuntimeSingleton<T>
8
11
  {
9
12
  public static bool HasInstance => _instance != null;
10
-
13
+
11
14
  protected static T _instance;
12
-
15
+
13
16
  protected virtual bool Preserve => true;
14
17
 
15
18
  public static T Instance
@@ -31,5 +34,24 @@
31
34
  return _instance;
32
35
  }
33
36
  }
37
+
38
+ protected virtual void Awake()
39
+ {
40
+ if (_instance == null)
41
+ {
42
+ _instance = this as T;
43
+ }
44
+ }
45
+
46
+ protected virtual void Start()
47
+ {
48
+ if (_instance != null && _instance != this)
49
+ {
50
+ this.LogError(
51
+ $"Double singleton detected, {_instance.name} conflicts with {name}."
52
+ );
53
+ gameObject.Destroy();
54
+ }
55
+ }
34
56
  }
35
- }
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc08",
3
+ "version": "2.0.0-rc09",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},