Doloro GDK 22 .1.0 Beta
by Tauri Interactive
Custom loading behavior

Idea

When you are using Asset Bundles Loader its frequent occasion when you want to handle loading resources on-fly to continue use in some systems to prevent any postponed calls and enumeration of the resources.

The best practice to make entire preparations possible to be made during initial game loading avoiding any time-consuming processes during gameplay.

The Resource Loading Behavior is the solution for such a task. In this category we introduce you into development process of custom solution and its integration into the loader.

See also:

Development

Rules

Warning
If you overrides Awake or OnDestroy members always calls its base body within overridden method.
protected override Awake()
{
// Skip will leave the behavior out of the loader.
// The component will not be called and resources
// will not be handler with your logic
base.Awake();
}
protected override OnDestroy()
{
// Skip will cause that the behavior will not be released from the loader instance.
base.Awake();
}

Skip of this will lead to critical or unexpected bugs.

Body

Doloro.DataManagement.AssetBundlesTools.AResourceLoadingBehavior has several important members that allows you to handle loading stages.

Message Purpose
Awake Regular Unity message that may be overridden to handle component initialization time.
OnDestroy Regular Unity message that may be overridden to handle release of unmanaged resources treated by the component.
OnLoadingStarted Loader message that occurs when a loading behavior gets its turn in loader's sequencer.
OnLoadingCompleted Occurs when loader notice that the loading behavior has been ended with a Complete state.
OnLoadingFailed Occurs when loader notice that the loading behavior has been ended with a Failed state.

OnLoadingStarted is only method that must be defined. The method should implement a logic that starts internal resources handling process.

Flow control

The control of the loader sequencer you have to manage Doloro.DataManagement.AssetBundlesTools.AResourceLoadingBehavior.State property value.

  • Before start the behavior has NotStarted state.
  • As soon as a behavior has been started it has State property switched to InProgress state.

When you may conclude that the behavior has ended its execution in have to set the State to some competence state:

State Meaning Consequences
Failed Behavior logic has been interrupted or filed to reach an expected result. OnLoadingFailed will be invoked by the loader.
Success behavior completed its logic with expected result. OnLoadingCompleted will be invoked by the loader.

Integration

Since any loading behavior is a Component by itself the only logical way to integrate it with a AssetBundlesLoader is to add the component instance to the same object where the loader are located.

The loader will automatically find the instance and add it to internal async sequencer. You no need to make any extra actions to perform this process.

Example

Doloro GDK has several implemented loaders that can be used as examples. You may find handful to explore them using following sections: