UltimateXR.Core.Components.Singleton Namespace

Classes

ClassDescription
Public classUxrAbstractSingleton<T>

A singleton base class that can be used with abstract classes.

The difference with UxrSingleton<T> is that UxrSingleton<T> guarantees that an instance will always be available in the scene by instantiating the component if it’s not found. This means Instance will always be non-null and can be used with or without an instance available in the scene. UxrSingleton<T> also allows to use automatic prefab instantiation if a compatible singleton prefab is present in a special Resources folder. Since abstract classes can’t be instantiated, Instance in UxrAbstractSingleton<T> will be non-null only if a child component is available somewhere in the scene.

For design purposes, a singleton may still be desirable when programming an abstract class, hence this UxrAbstractSingleton<T> component base class.

Public classUxrAsyncInitAbstractSingleton<T> Same as UxrAsyncInitSingleton<T> but allows asynchronous initialization. This can be useful where singletons require initialization through config files that are loaded asynchronously from disk or through network.
Public classUxrAsyncInitSingleton<T> Same as UxrSingleton<T> but allows asynchronous initialization. This can be useful where singletons require initialization through config files that are loaded asynchronously from disk or through network.
Public classUxrSingleton<T>

An improved singleton implementation over UxrAbstractSingleton<T> for non-abstract classes. UxrSingleton<T> guarantees that an Instance will always be available by instantiating the singleton if it wasn’t found in the scene. Additionally, it can instantiate a prefab if there is one available in a well-known location.

The steps followed by this singleton implementation to assign the instance are the:  

  1. The singleton component is searched in the scene to see if it was pre-instantiated or is already available.
  2. If not found, the component tries to be instantiated in the scene using a prefab in a well known Resources folder. The well known path is SingletonResources in any Resources folder and the prefab name is the singleton class name. A prefab allows to assign initial properties to the component and also hang additional resources (meshes, textures) from the GameObject if needed.
  3. If not found, a new GameObject is instantiated and the singleton is added using AddComponent``1().