DoopelPonger
Public Member Functions | Static Public Member Functions | Properties | List of all members
Singleton< T > Class Template Reference

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...

Inheritance diagram for Singleton< T >:
Inheritance graph
[legend]
Collaboration diagram for Singleton< T >:
Collaboration graph
[legend]

Public Member Functions

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...
 

Static Public Member Functions

static void SetInstance (T instance)
 

Properties

static T Instance [get, set]
 

Detailed Description

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.

Type Constraints
T :MonoBehaviour 

Member Function Documentation

◆ OnDestroy()

void Singleton< T >.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 ( instance)
static

Property Documentation

◆ Instance

T Singleton< T >.Instance
staticgetset

The documentation for this class was generated from the following file: