Be aware this will not prevent a non singleton constructor such as T myT = new T();
To prevent that, add protected T () {}
to your singleton class.
More...
|
void | 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. More...
|
|
Be aware this will not prevent a non singleton constructor such as T myT = new T();
To prevent that, add protected T () {}
to your singleton class.
Class used everywhere to inforce the singleton pattern. It was original taken from http://wiki.unity3d.com/index.php/Singleton. Small modifications have been made.
As a note, this is made as MonoBehaviour because we need Coroutines.
◆ 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.
◆ SetInstance()
static void Singleton< T >.SetInstance |
( |
T |
instance | ) |
|
|
static |
◆ Instance
The documentation for this class was generated from the following file: