







![]() |
ClockStone Audio Toolkit for Unity - Documentation |
SingletonMonoBehaviour<(Of <(<'T>)>)> Class |
Members Example See Also Send Feedback |
![]() |
Provides singleton-like access to a unique instance of a MonoBehaviour.
Namespace: (Default Namespace)
Assembly: AudioToolkit (in AudioToolkit.dll) Version: 8.0.0.0 (8.0.0.0)
Syntax
C# |
---|
public abstract class SingletonMonoBehaviour<T> : MonoBehaviour, ISingletonMonoBehaviour where T : MonoBehaviour |
Type Parameters
- T
- Your singleton MonoBehaviour
Remarks
Makes sure that an instance is available from other Awake() calls even before the singleton's Awake()
was called. ( Requires AwakeSingleton() !)
Examples
Derive your own class from SingletonMonoBehaviour.
![]() | |
---|---|
public class MyScriptClass : SingletonMonoBehaviour<MyScriptClass> { public MyScriptClass() { MyScriptClass.SetSingletonType( typeof( MyScriptClass ) ); // workaround for Flash } public void MyFunction() { } protected override void Awake() { base.Awake(); } void AwakeSingleton() { // all initialisation code here. Will get called from Awake() by singleton. // Can get called before Awake() if an instance is accessed in an Awake() function which // was called earlier } } |
access the instance by writing
![]() | |
---|---|
MyScriptClass.Instance.MyFunction(); |
Inheritance Hierarchy
System..::..Object
Object
Component
Behaviour
MonoBehaviour
(Default Namespace)..::..SingletonMonoBehaviour<(Of <(<'T>)>)>
(Default Namespace)..::..AudioController
Object
Component
Behaviour
MonoBehaviour
(Default Namespace)..::..SingletonMonoBehaviour<(Of <(<'T>)>)>
(Default Namespace)..::..AudioController