Interhaptics SDK for Unity 1.6
Loading...
Searching...
No Matches
Interhaptics.Internal.Singleton< T > Class Template Referenceabstract
Inheritance diagram for Interhaptics.Internal.Singleton< T >:

Protected Member Functions

virtual void OnAwake ()
 
virtual void OnOnApplicationQuit ()
 

Properties

static bool Quitting [get]
 
static T Instance [get]
 

Detailed Description

Type Constraints
T :MonoBehaviour 

Definition at line 12 of file Singleton.cs.

Member Function Documentation

◆ OnAwake()

virtual void Interhaptics.Internal.Singleton< T >.OnAwake ( )
protectedvirtual

Definition at line 91 of file Singleton.cs.

91{ }

◆ OnOnApplicationQuit()

virtual void Interhaptics.Internal.Singleton< T >.OnOnApplicationQuit ( )
protectedvirtual

Definition at line 93 of file Singleton.cs.

93{ }

Property Documentation

◆ Instance

T Interhaptics.Internal.Singleton< T >.Instance
staticget

Definition at line 27 of file Singleton.cs.

28 {
29 get
30 {
31 if (Quitting)
32 {
33 Debug.LogWarning($"[Singleton<{typeof(T)}>] Instance will not be returned because the application is quitting.");
34 return null;
35 }
36 lock (Lock)
37 {
38 if (_instance != null)
39 {
40 return _instance;
41 }
42
43 var instances = FindObjectsOfType<T>();
44 var count = instances.Length;
45 if (count == 0)
46 {
47 Debug.Log($"[Singleton<{typeof(T)}>] An instance is needed in the scene and no existing instances were found, so a new instance will be created.");
48 return _instance = new GameObject($"(Singleton){typeof(T)}").AddComponent<T>();
49 }
50 if (count > 1)
51 {
52 Debug.LogWarning($"[Singleton<{typeof(T)}>] There should never be more than one Singleton of type {typeof(T)} in the scene, but {count} were found. The first instance found will be used, and all others will be destroyed.");
53 for (var i = 1; i < instances.Length; i++)
54 {
55 Destroy(instances[i]);
56 }
57 }
58
59 return _instance = instances[0];
60 }
61 }
62 }

◆ Quitting

bool Interhaptics.Internal.Singleton< T >.Quitting
staticget

Definition at line 25 of file Singleton.cs.

25{ get; private set; }

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