Init(args)
Scripting Reference
List of all members | Public Member Functions | Public Attributes | Properties
Sisus.Init.ServiceAttribute Class Reference

Description

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:

Inherits Attribute.

Public Member Functions

 ServiceAttribute ()
 Classes that have the ServiceAttribute can provide services for one or more client objects. More...
 
 ServiceAttribute ([CanBeNull] Type definingType)
 Classes that have the ServiceAttribute can provide services for one or more client objects. More...
 

Public Attributes

readonly Type definingType
 Class or interface type that uniquely defines the service and can be used to retrieve an instance of the it. More...
 

Properties

string? ResourcePath [get, set]
 Resources path from which an instance of the service can be loaded during initialization. More...
 
bool FindFromScene [get, set]
 If true then an instance of the service component will be loaded from the initial scene. More...