Tilt Five Unity API  1.3.0
Protected Member Functions | Properties | Static Private Attributes | List of all members
TiltFive.SingletonComponent< T > Class Template Reference
Inheritance diagram for TiltFive.SingletonComponent< T >:

Protected Member Functions

virtual void Awake ()
 

Properties

static T Instance [get]
 

Static Private Attributes

static T s_Instance = null
 

Detailed Description

Type Constraints
T :UnityEngine.MonoBehaviour 

Definition at line 45 of file Singleton.cs.

Member Function Documentation

◆ Awake()

virtual void TiltFive.SingletonComponent< T >.Awake ( )
protectedvirtual

Reimplemented in TiltFive.TiltFiveManager2, TiltFive.TiltFiveManager, and TiltFive.Display.

Definition at line 102 of file Singleton.cs.

103  {
104  if(s_Instance == null)
105  {
107  }
108  }

References TiltFive.SingletonComponent< T >.Instance, and TiltFive.SingletonComponent< T >.s_Instance.

Member Data Documentation

◆ s_Instance

T TiltFive.SingletonComponent< T >.s_Instance = null
staticprivate

Definition at line 47 of file Singleton.cs.

Referenced by TiltFive.SingletonComponent< T >.Awake().

Property Documentation

◆ Instance

T TiltFive.SingletonComponent< T >.Instance
staticget

Definition at line 48 of file Singleton.cs.

49  {
50  get
51  {
52  if( s_Instance != null )
53  {
54  return s_Instance;
55  }
56 
57  T[] instances = Resources.FindObjectsOfTypeAll<T>();
58  if( instances != null )
59  {
60 
61  // find the one that is actually in the scene (and not the editor)
62  for( int i = 0; i < instances.Length; ++i )
63  {
64  T instance = instances[ i ];
65  if( instance == null )
66  {
67  continue;
68  }
69 
70  if( instance.hideFlags != HideFlags.None )
71  {
72  continue;
73  }
74 
75  // avoid selecting component attached to a prefab asset that isn't in scene
76  if( string.IsNullOrEmpty(instance.gameObject.scene.name) )
77  {
78  continue;
79  }
80 
81  s_Instance = instance;
82  DontDestroyOnLoad( s_Instance );
83  break;
84  }
85  }
86 
87 
88  if( s_Instance == null )
89  {
90  string name = string.Format( "__{0}__", typeof( T ).FullName );
91  GameObject singletonGo = new GameObject( name );
92  s_Instance = singletonGo.AddComponent<T>();
93  DontDestroyOnLoad( s_Instance );
94  }
95 
96  return s_Instance;
97  }
98  }

Referenced by TiltFive.SingletonComponent< T >.Awake(), and TiltFive.TiltFiveSingletonHelper.TryGetISceneInfo().


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