![]() |
Init(args)
Scripting Reference
|
Classes that have the ServiceAttribute can provide services for one or more client objects.
A single instance of each class that has the attribute will automatically get loaded behind the scenes making them ready for clients to retrieve as needed.
Objects deriving from MonoBehaviour<TDefiningClassOrInterface> or ScriptableObject<TDefiningClassOrInterface> receive the service during initialization automatically.
Other clients can retrieve a service by implementing the IArgs<TDefiningClassOrInterface> interface and calling InitArgs.TryGet<TClient, TDefiningClassOrInterface> during initialization.
It is possible to receive more than one services automatically by implementing an IArgs{} interface with more than one service argument (upto a maximum of five).
Services can also receive other services during initialization by implementing an IInitializable<TService> interface targeting the services they depend on.
Initializer<> classes are also able to retrieve all service instances automatically and inject them to the client's Init method.
Service<TDefiningClassOrInterface>.Instance can be used to manually retrieve a service object.
Service objects that implement IAwake, IOnEnable or IStart receive the relevant event after all services have been created and all services have received the other services they depend on.
A service can optionally receive callbacks during select unity event functions by implementing one or more of the following interfaces:
Public Member Functions | |
ServiceAttribute (params Type[] definingTypes) | |
Classes that have the ServiceAttribute can provide services for one or more client objects. | |
Public Attributes | |
readonly Type[] | definingTypes |
Class or interface type that uniquely defines the service and can be used to retrieve an instance of it. | |
Properties | |
string | ResourcePath [get, set] |
Resources path from which an instance of the service can be loaded during initialization. | |
bool | FindFromScene [get, set] |
If true then an instance of the service will be loaded from the initial scene. | |
string | SceneName [get, set] |
The name of the scene containing the service, if provided; otherwise, an empty string. | |
int | SceneBuildIndex [get, set] |
The name of the scene containing the service, if provided; otherwise, an empty string. | |
bool? | Instantiate [get, set] |
If true , then service instance will be a direct reference to an asset that is loaded using a resource path or an addressable key. | |
bool | LazyInit [get, set] |
If set to true then an instance of the service will only be created on demand when the first client requests and instance. | |
bool | LoadAsync [get, set] |
If set to true then the service will be loaded asynchronously if possible. | |