09. ScriptableWrapper

  03. Features No Comments

The ScriptableWrapper class is a ScriptableObject that can act as a simple wrapper for a plain old class object.

It makes it easy to take a plain old class object, serialize it as an asset in the project.

Let’s say you had a plain old class called Settings:

public class Settings { }

To create a scriptable wrapper for the Settings class, make a class that inherits from ScriptableWrapper<Settings>.

public class SettingsAsset : ScriptableWrapper<Settings> { }

This wrapper implements IInitializable<Settings>, which means that a new instance can be initialized with the Player object passed as an argument using any of the various methods listed in the Creating Instances section.

For example, the Player can be attached to a GameObject using the following syntax:

Player player = new Player();
gameObject.AddComponent<PlayerComponent, Player>(player);

Unity Events

Wrapped objects can receive callbacks during select Unity events from their wrapper by implementing one of the following interfaces:

  1. IAwake – Receive callback during the ScriptableObject.Awake event.
  2. IOnEnableReceive callback during the ScriptableObject.OnEnable event.
  3. IUpdate Receive callback during the Update event.
  4. IFixedUpdateReceive callback during the FixedUpdate event.
  5. ILateUpdateReceive callback during the LateUpdate event.
  6. IOnDisableReceive callback during the ScriptableObject.OnDisable event.
  7. IOnDestroyReceive callback during the ScriptableObject.OnDestroy event.

Leave a Reply

Your email address will not be published. Required fields are marked *