![]() |
Init(args)
Scripting Reference
|
A base class for a component that can can specify the argument used to initialize an object that implements IInitializable<TArgument>.
The arguments can be assigned using the inspector and are serialized as part of the client's scene or prefab asset.
The arguments get injected to the TClient client during the Awake event.
The client receives the arguments via the Init method where it can be assigned to a member field or a property.
After the arguments have been injected the initializer is removed from the GameObject that holds it.
When you derive your Initializer class from InitializerBase<,> you are responsible for implementing the argument properties and serializing their value. This means you will need to write a little bit more code, but it also grants you more options in how to handle the serialization, making it possible to support types that Unity can't serialize automatically. If you derive from Initializer<,> instead, then these things will be handled for you.
TClient | Type of the initialized client component. |
TArgument | Type of the argument to pass to the client component's Init function. |
TClient | : | MonoBehaviour | |
TClient | : | IInitializable<TArgument> |
Protected Member Functions | |
override TClient | InitTarget ([AllowNull] TClient target) |
virtual void | OnReset (ref TArgument argument) |
Resets the Init argument to its default value. | |
Properties | |
TArgument | Argument [get, set] |
The argument passed to the TClient client's Init function. | |
![]() | |
Object | Target [get, set] |
Existing target instance to initialize, if any. | |
bool | ProvidesCustomInitArguments [get] |
Gets a value indicating whether this initializer is able to provide custom per-instance Init arguments for its client. | |
Additional Inherited Members | |
![]() | |
new TClient | InitTarget () |
Initializes the client object of type TClient with the arguments specified by this initializer. | |
new System.Threading.Tasks.Task< TClient > | InitTargetAsync () |
Initializes the client object of type TClient asynchronously with the arguments specified by this initializer. | |
![]() | |
bool | TargetIsAssignableOrConvertibleToType (Type type) |
Gets a value indicating whether an object of the given type can be assigned to the Target property directly, or if type implements IValueProvider<T>, IValueByTypeProvider or IValueByTypeProviderAsync. | |