Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
ManlySingleton.cs
Go to the documentation of this file.
1using UnityEngine;
2
3public class ManlySingleton<T> : SingletonBase where T : MonoBehaviour
4{
5 private static T myInstance;
6
7 public static T Instance
8 {
9 get
10 {
11 if (myInstance == null)
12 {
13 Object[] array = Object.FindObjectsOfType(typeof(T));
14 if (array.Length > 1)
15 {
16 Debug.LogError("<B>Doubleton?</B> Do you really want two instances of <B><i>" + typeof(T).Name + "</i></B>?\n", array[1]);
17 }
18 if (array.Length >= 1)
19 {
20 myInstance = (T)array[0];
21 }
22 if (myInstance == null)
23 {
24 Debug.LogError("An instance of " + typeof(T).Name + " could not be found. Add it to the scene.");
25 }
26 }
27 return myInstance;
28 }
29 }
30
31 public static T InstanceOrNull => myInstance ?? (myInstance = (T)Object.FindObjectOfType(typeof(T)));
32
33 public static Transform STransform => Instance.transform;
34
35 public static Vector3 SPosition
36 {
37 get
38 {
39 return Instance.transform.position;
40 }
41 set
42 {
43 Instance.transform.position = value;
44 }
45 }
46
47 public static GameObject SGameObject => Instance.gameObject;
48
49 public static bool Exists()
50 {
51 return InstanceOrNull != null;
52 }
53
54 public override void Elect()
55 {
56 myInstance = this as T;
57 }
58
59 protected void Abdicate()
60 {
61 if (myInstance == this)
62 {
63 myInstance = null;
64 }
65 }
66
67 protected virtual void OnDestroy()
68 {
69 myInstance = null;
70 }
71}
static T?? Instance
override void Elect()
static GameObject SGameObject
static Transform STransform
static T InstanceOrNull
static T myInstance
static Vector3 SPosition
virtual void OnDestroy()
static bool Exists()