Class Service<T>
A Service is a singleton MonoBehaviour with certain capibilities in Unity.
Inheritance
Inherited Members
Namespace: NoSuchStudio.Common.Service
Assembly: NoSuchStudio-Common.dll
Syntax
public abstract class Service<T> : NoSuchMonoBehaviour where T : Service<T>
Type Parameters
| Name | Description |
|---|---|
| T |
Remarks
This class serves as a singleton for Unity. A Service:
- Ensures there is at most one Instance of the MonoBehaviour Active at any given point in time. If another Intance becomes Active, the old one will go offline.
- Provides a static API surface through the currently Active Instance. Individual services can provide fallback methods in cases there is no Instance for the service.
- Will find all Components that use it in the Scene initially and connects them. IServiceComponent<T>
Fields
_instanceReady
Declaration
protected bool _instanceReady
Field Value
| Type | Description |
|---|---|
| Boolean |
gInstance
The global instance of this NoSuchStudio.Common.Service. For normal usage, use RegisterInstance(T) and UnregisterInstance(T).
Declaration
protected static T gInstance
Field Value
| Type | Description |
|---|---|
| T |
needsEditorRepaint
Declaration
[NonSerialized]
public bool needsEditorRepaint
Field Value
| Type | Description |
|---|---|
| Boolean |
Properties
Instance
The property for accessing the global instance of this NoSuchStudio.Common.Service. For normal usage, use RegisterInstance(T) and UnregisterInstance(T).
Declaration
public static T Instance { get; protected set; }
Property Value
| Type | Description |
|---|---|
| T |
InstanceReady
Declaration
public bool InstanceReady { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
IsInstance
Checks if the current instance is the global instance.
Declaration
public bool IsInstance { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
IsReady
Declaration
public static bool IsReady { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Methods
OnDisable()
Declaration
protected virtual void OnDisable()
OnEnable()
Declaration
protected virtual void OnEnable()
OnServiceRegister()
Callback for when an instance becomes the global instance.
Declaration
public virtual void OnServiceRegister()
OnServiceUnregister()
Callback for when an instance is no longer the global instance.
Declaration
public virtual void OnServiceUnregister()
RegisterInstance(T)
Service instances call this OnEnable to become the global instance.
Declaration
protected static void RegisterInstance(T instance)
Parameters
| Type | Name | Description |
|---|---|---|
| T | instance |
ReRegisterService()
Same effect as disabling and enabling the service instance.
Declaration
public void ReRegisterService()
UnregisterInstance(T)
Service instances call this OnDisable to release the global instance.
Declaration
protected static void UnregisterInstance(T instance)
Parameters
| Type | Name | Description |
|---|---|---|
| T | instance |