Singleton
GlacierSingleton
This is for basic C# classes. This is not for MonoBehaviours or ScriptableObjects.
namespace Sample001 {
public class SingletonSample : GlacierSingleton<SingletonSample> {
protected override void Initialize() {
GlacierLog.Log("SingletonSample.Initialize() gets called.");
}
public void Test() {
GlacierLog.Log("SingletonSample working.");
}
}
}
SingletonSample.Instance.Test();
GlacierMonoSingleton
This is for MonoBehaviours. No need to call CreateInstance since Unity handles the instantiation.
[!error]DO NOT implement Awake() because it will override the logic of handling the singleton instance.
namespace Sample001 {
public class MonoSingletonSample : MonoSingleton<MonoSingletonSample> {
protected override void Initialize() {
GlacierLog.Log("MonoSingletonSample.Initialize() gets called.");
}
public void Test() {
GlacierLog.Log("MonoSingletonSample working.");
}
}
}
SingletonSample.Instance.Test();