![]() |
Init(args)
Scripting Reference
|
This attribute can be added to a class that derives from one of the MonoBehaviour<T> base classes to automatically initialize it with dependencies when the component is first attached to a GameObject in the editor or when the user selects 'Reset' in the Inspector's context menu.
The dependencies are automatically retrieved from the scene hierarchy, relative to the GameObject that contains the MonoBehaviour<T>. You can specify From where Object arguments should be searched, or use the default search mode, which tries to pick a good search mode to use based on the type of the argument:
The found arguments are passed to the component's IInitializable<T>.Init function, where they can be assigned to serialized fields.
This behaviour only occurs in edit mode and is meant to make it more convenient to add components without needing to assign all Object references manually using the inspector.
This attribute can also be added to classes that derive from one of the InitializerBase<T> base classes. In this case the end result is the same, except the arguments are routed into the initializer instead.
Public Member Functions | |
InitOnResetAttribute () | |
When a component that derives from MonoBehaviour<T> and has the InitOnResetAttribute is first added to a GameObject in the editor, or when the user hits the Reset button in the Inspector's context menu, the arguments accepted by the component are automatically gathered and passed to its IInitializable<T>.Init function. | |
InitOnResetAttribute (From search) | |
When a component that derives from MonoBehaviour<T> and has the InitOnResetAttribute is first added to a GameObject in the editor, or when the user hits the Reset button in the Inspector's context menu, the arguments accepted by the component are automatically gathered and passed to its IInitializable<T>.Init function. | |
InitOnResetAttribute (From first, From second, From third=defaultFrom, From fourth=defaultFrom, From fifth=defaultFrom, From sixth=defaultFrom) | |
When a component that derives from MonoBehaviour<T> and has the InitOnResetAttribute is first added to a GameObject in the editor, or when the user hits the Reset button in the Inspector's context menu, the arguments accepted by the component are automatically gathered and passed to its IInitializable<T>.Init function. | |
Public Attributes | |
readonly From | first |
Defines where to search when trying to retrieve the first dependency of the attribute holder. | |
readonly From | second |
Defines where to search when trying to retrieve the second dependency of the attribute holder. | |
readonly From | third |
Defines where to search when trying to retrieve the third dependency of the attribute holder. | |
readonly From | fourth |
Defines where to search when trying to retrieve the fourth dependency of the attribute holder. | |
readonly From | fifth |
Defines where to search when trying to retrieve the fifth dependency of the attribute holder. | |
readonly From | sixth |
Defines where to search when trying to retrieve the sixth dependency of the attribute holder. | |