Class MonoSingleton<T>
Singleton pattern implementation. Can be used with classes extended from a MonoBehaviour. Once instance is found or created, game object will be marked as DontDestroyOnLoad.
Inheritance
Namespace: StansAssets.Foundation.Patterns
Assembly: cs.temp.dll.dll
Syntax
public abstract class MonoSingleton<T> : MonoBehaviour where T : MonoBehaviour
Type Parameters
Name | Description |
---|---|
T |
Properties
HasInstance
Returns true
if Singleton Instance exists.
Declaration
public static bool HasInstance { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Instance
Returns a singleton class instance If current instance is not assigned it will try to find an object of the instance type, in case instance already exists on a scene. If not, new instance will be created
Declaration
public static T Instance { get; }
Property Value
Type | Description |
---|---|
T |
IsDestroyed
If this property returns true
it means that object with explicitly destroyed.
This could happen if Destroy function was called for this object or if it was
automatically destroyed during the ApplicationQuit
.
Declaration
public static bool IsDestroyed { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
Awake()
Declaration
protected virtual void Awake()
OnApplicationQuit()
Declaration
protected virtual void OnApplicationQuit()
OnDestroy()
When Unity quits, it destroys objects in a random order. In principle, a Singleton is only destroyed when application quits. If any script calls Instance after it have been destroyed, it will create a buggy ghost object that will stay on the Editor scene even after stopping playing the Application. Really bad! So, this was made to be sure we're not creating that buggy ghost object.
Declaration
protected virtual void OnDestroy()