Customize Behaviour - Katsuya100/SceneLayer-Trial GitHub Wiki
Summary
The scene layer is composed by combining three types of data.
- Layer
Data representing a unit of one screen. - Transition
Data representing transitions between layers. - Loader
Data representing the components in a Layer.
These data are similar to those of MonoBehaviour, which is a They are customizable Behaviour and can be inherited and implemented freely.
Some custom Behaviours are also available as presets. However, for more flexible game development, customization may be necessary for specific projects.
This page explains how to create a custom Behaviour.
Custom Layer
To customize a Layer, inherit from LayerBehaviour
.
Since a Layer is data that represents a unit of a single screen, it eliminates the need for awkward components that conventionally tend to be placed at the root of the scene.
In addition, when transferring data during screen transitions, it used to be necessary to "escape data to DontDestroyOnload before unloading." but since all layers are always on-memory, it is possible to "transfer the data held in a layer to the next layer as it is.
Create Script
- Select [Right-click > Create > SceneLayer > Layer Behaviour] on the Project view.
- Enter a name for the LayerBehaviour.(Example:
Title
) - Right-click on the SceneLayerEditor.
- Create a Layer and select
BehaviourType
from Inspector. - Set up the Script you just created.
Event Callback
OnInitialize
Initialization process.
Called only once.
OnEntry
Processing at Layer Entry.
The initialization process to be performed each time a scene is opened should be written here.
OnExit
Processing at Layer Exit.
Destruction processing to be performed each time you leave the scene should be written here.
OnUpdate
Processing at Layer Update.
Called every frame between OnEntry and OnExit.
OnTransit something
A callback county that describes the transition process.
It is a coroutine, and the transition is not complete until this callback is completed.
Therefore, if there are items that need to be loaded manually, or if you want to prepare a transitional effect, you can implement it here.
The call timing and layer rules for each event function are as follows
Event Callback | Timing | Call Layer |
---|---|---|
OnPreTransitFrom | Before transition starts. | Destination |
OnPreTransitTo | Before transition starts. | Source |
OnTransitFrom | In transition. | Destination |
OnTransitTo | In transition. | Source |
OnPostTransitFrom | After transition completed. | Destination |
OnPostTransitTo | After transition completed. | Source |
OnPreParentTransitFrom | Before transition starts of the parent Layer. | Child Layer of Destination |
OnPreParentTransitTo | Before transition starts of the parent Layer. | Child Layer of Source |
OnParentTransitFrom | In transition of the parent Layer. | Child Layer of Destination |
OnParentTransitTo | In transition of the parent Layer. | Child Layer of Source |
OnPostParentTransitFrom | After transition completed of the parent Layer. | Child Layer of Destination |
OnPostParentTransitTo | After transition completed of the parent Layer. | Child Layer of Source |
OnPreChildTransit | efore transition starts of the child Layer. | Parent Layer of destination and source |
OnChildTransit | In transition of the child Layer. | Parent Layer of destination and source |
OnPostChildTransit | After transition completed of the child Layer. | Parent Layer of destination and source |
In transition … Between OnExit and OnEntry
Before transition starts … Before OnExit
After transition completed … After OnEntry
See Sequence Events for more information.
OnCheckError
Error checking process.
If there is an error in the input parameters, the If error information is added to the passed argument, it can be checked on the editor and can be detected as a runtime error at startup.
// Arg1:Error message (required)
// Others:The name of the SerializeField that caused the problem, if any.
result.Add(new ErrorObject("Error Message.", nameof(_reasonMember)));
OnDuplicatedAsset (for editors)
Processing when duplicating an asset.
The source of the duplicate is passed as an argument.
If there is a value you want to take over when duplicating an asset, you can copy it.
OnChangeBehaviourTo (for editors)
Processing at the time of Behaviour change.
If there are any values you want to inherit from LayerBehaviour
after the change, you can copy them here.
Custom Transition
To customize a Transition, extend TransitionBehaviour
.
Customizing transitions makes it possible to programmatically describe transition conditions.
It is also possible to describe events during transitions, making it possible to implement common processes such as "clearing the cache during transition" in one place.
Crete Script
- Select [Right click > Create > SceneLayer > Transition Behaviour] on the Project view.
- Enter a name for the LayerBehaviour.(Example:
Title
) - Right-click on a layer in the SceneLayerEditor.
- Create a Transition and select
BehaviourType
from Inspector. - Specify the Script you just created.
Event Callback
IsTransitable(Required)
If Transition
is enabled, this function is checked every frame.
If true is returned when a transition is enabled, the transition is executed.
OnInitialize
Initialization process.
Called only once.
OnTransit something
A callback county that describes the transition process.
These callbacks are coroutines, and the transition is not complete until this callback is completed.
Therefore, if there is processing that needs to be done before the transition completes, it should be implemented here.
Event Callback | Timing |
---|---|
OnPreTransit | Before transition starts. |
OnTransit | In transition. |
OnPostTransit | After transition completed. |
In transition … Between OnExit and OnEntry
Before transition starts … Before OnExit
After transition completed … After OnEntry
See Sequence Events for more information.
OnCheckError
Error checking process.
If there is an error in the input parameters, the If error information is added to the passed argument, it can be checked on the editor and can be detected as a runtime error at startup.
// Arg1:Error message (required)
// Others:The name of the SerializeField that caused the problem, if any.
result.Add(new ErrorObject("Error Message.", nameof(_reasonMember)));
OnDuplicatedAsset (for editors)
Processing when duplicating an asset.
The source of the duplicate is passed as an argument.
If there is a value you want to take over when duplicating an asset, you can copy it.
OnChangeBehaviourTo (for editors)
Processing at the time of Behaviour change.
If there are any values you want to inherit from TransitionBehaviour
after the change, you can copy them here.
Custom Loader
Loader inherits from LoaderBehaviour
for customization.
The Loader is responsible for loading, generating, destroying, and releasing screen elements in a registered Layer.
However, the actual asset management varies from project to project.
Customization is expected to go through a project-specific asset manager.
Create Script
- Select [Right click > Create > SceneLayer > Loader Behaviour] on the Project view.
- Enter a name for the Loader.(Example:
AssetLoader
) - Open Script and implement the process of your choice.
- Open Layer's Inspector.
- Create a Loader from the [+] button and select `BehaviourType.
- Specify the Script you just created.
Event Callback
GetInstance(Required)
Return the instantiated instance.
GetInstanceType(Required)
Returns the type of instance to be instantiated.
If the type is unknown, object is acceptable, but it is preferable that the type is narrowed down as much as possible.
If the type is narrowed down, it will be easier to use Receive Loader instance events in Layer.
Load(Required)
Loading process.
If you want to use your own loading process or asset manager, implement it here.
(You can write the loading process in LayerBehaviour.OnTransit something, but it is recommended to implement it here because it can handle preloading.)
It is also possible to load multiple assets that do not have a specific target at once.
Unload(Required)
Release process.
InstantiateObject(Required)
Make the loaded object ready for use.
If it is a GameObject, Instantiate.
If it is a Scene, LoadSceneAsync.
If it is a BGM, you may start playback here.
DestroyObject(Required)
Destroy instances created by InstantiateObject.
OnInitialize
Initialization process.
Called only once.
OnCheckError
Error checking process.
If there is an error in the input parameters, the If error information is added to the passed argument, it can be checked on the editor and can be detected as a runtime error at startup.
// Arg1:Error message (required)
// Others:The name of the SerializeField that caused the problem, if any.
result.Add(new ErrorObject("Error Message.", nameof(_reasonMember)));
OnDuplicatedAsset (for editors)
Processing when duplicating an asset.
The source of the duplicate is passed as an argument.
If there is a value you want to take over when duplicating an asset, you can copy it.
OnChangeBehaviourTo (for editors)
Processing at the time of Behaviour change.
If there are any values you want to inherit from LoaderBehaviour
after the change, you can copy them here.