Iuvo Unity 0.5.1
This is library containing a variety of helper classes and extension methods for the Unity gane engine.
GitHub | Iuvo Unity Updates | Creator
Loading...
Searching...
No Matches
IuvoUnity.Singletons.PersistentSingleton< T > Class Template Reference
Inheritance diagram for IuvoUnity.Singletons.PersistentSingleton< T >:
IuvoUnity.Singletons.CoroutineManager IuvoUnity.Singletons.GravityManager

Public Attributes

bool UnparentOnAwake = true

Protected Member Functions

virtual void Awake ()
virtual void InitializeSingleton ()

Static Protected Attributes

static T instance

Properties

static bool HasInstance [get]
static T Current [get]
static T Instance [get]

Member Function Documentation

◆ Awake()

virtual void IuvoUnity.Singletons.PersistentSingleton< T >.Awake ( )
protectedvirtual

Reimplemented in IuvoUnity.Singletons.CoroutineManager, and IuvoUnity.Singletons.GravityManager.

38=> InitializeSingleton();

References InitializeSingleton().

◆ InitializeSingleton()

virtual void IuvoUnity.Singletons.PersistentSingleton< T >.InitializeSingleton ( )
protectedvirtual
41 {
42 if (!Application.isPlaying)
43 {
44 return;
45 }
46
47 if (UnparentOnAwake)
48 {
49 transform.SetParent(null);
50 }
51
52 if (instance == null)
53 {
54 instance = this as T;
55 DontDestroyOnLoad(transform.gameObject);
56 enabled = true;
57 }
58 else
59 {
60 if (this != instance)
61 {
62 Destroy(this.gameObject);
63 }
64 }
65 }

References instance, and UnparentOnAwake.

Referenced by Awake().

Member Data Documentation

◆ instance

T IuvoUnity.Singletons.PersistentSingleton< T >.instance
staticprotected

Referenced by InitializeSingleton().

◆ UnparentOnAwake

bool IuvoUnity.Singletons.PersistentSingleton< T >.UnparentOnAwake = true

Referenced by InitializeSingleton().

Property Documentation

◆ Current

T IuvoUnity.Singletons.PersistentSingleton< T >.Current
staticget

◆ HasInstance

bool IuvoUnity.Singletons.PersistentSingleton< T >.HasInstance
staticget

◆ Instance

T IuvoUnity.Singletons.PersistentSingleton< T >.Instance
staticget
20 {
21 get
22 {
23 if (instance == null)
24 {
25 instance = FindFirstObjectByType<T>();
26 if (instance == null)
27 {
28 GameObject obj = new GameObject();
29 obj.name = typeof(T).Name + "AutoCreated";
30 instance = obj.AddComponent<T>();
31 }
32 }
33
34 return instance;
35 }
36 }

Referenced by IuvoUnity.IuvoPhysics.GravityBody.CalculateGravity(), and IuvoUnity.Singletons.CoroutineManager.RunCoroutine().


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