Class SingletonBehaviour<T>
A singleton MonoBehaviour that inherits from SuperBehaviour.
Implements a thread-safe singleton pattern as a inheritable base class.
public class GameManager : SingletonBehaviour<GameManager>
{
// ...
}
This approach ensures that each subclass (GameManager, UIManager, etc.) functions as a singleton, inheriting the singleton behavior from the base Manager class.
// Base class with generic type parameter T for singleton management
public class Manager<T> : SingletonBehaviour<T> where T : SuperBehaviour { }
// Derived singleton classes
public class GameManager : Manager<GameManager> { }
public class UIManager : Manager<UIManager> { }
public class SingletonBehaviour<T> : SuperBehaviour where T : SuperBehaviour
Type Parameters
T
The type of the class to use for the singleton.
- Inheritance
-
SingletonBehaviour<T>
- Derived
- Inherited Members
Fields
s_instance
protected static T s_instance
Field Value
- T
s_lock
protected static readonly object s_lock
Field Value
Properties
Exists
Returns if Instance is not null.
public static bool Exists { get; }
Property Value
Instance
The singleton instance of this class.
public static T Instance { get; }
Property Value
- T
Methods
AfterAwake()
Override this method to do something after singleton Awake() is called.
protected virtual void AfterAwake()
OnAfterDestroy()
Override this method to do something after singleton OnDestroy() is called.
protected virtual void OnAfterDestroy()