Skip to main content

Quick Start

Creating Kassets' ScriptableObjects

Instances of Kassets can be created from the Create context menu or from Assets/Create menu bar. Simply right click in the Project window and select the type of instance you want to create.

Create a GameEvent Instance

For GameEvent instances, select any of the provided event types from Create/Kassets/Game Events/

CreateEvent

Create a Variable Instance

For Variable instances, select any of the provided variable types from Create/Kassets/Variables/

CreateVariable

Below are the preview of Kassets' Variable instance on Inspector window.

Screenshot 2023-06-12 at 16 34 50

Using Kassets' ScriptableObject Instances

Usage on MonoBehavior Script

Create a MonoBehavior script and add Kassets' instance as a serialized field.

Player.cs :

Screen Shot 2020-11-16 at 20 47 36 copy

HealthBarUI.cs :

Screen Shot 2020-11-16 at 21 06 10 copy

Drag and drop PlayerHealth (FloatVariable) to Player's Health field :

Screen Shot 2020-11-19 at 6 25 46

Drag and drop PlayerHealth (FloatVariable) to HealthBarUI's Health field :

Screen Shot 2020-11-19 at 6 26 08

From the example above, Player component's field Health and HealthBarUI component's field Health both refer to the same FloatVariable ScriptableObject instance PlayerHealth. Since both components refer to the same variable instance, the float value they refer to is shared. Each component then manages its own need with the value without any coupling between components. For instance, HealthBarUI doesn't need to request the Health value from the Player component and the Player component can manage its own Health value without needing to distribute it to other components.

Raising and Subscribing to an Event

Both Player and HealthBarUI components manage their own instances of the shared PlayerHealth value. However, they still need a system of communication for accurate data sharing, which is where the Pub/Sub pattern becomes essential.

The Player component, as the Publisher, raises an event whenever there's a change to PlayerHealth. The HealthBarUI component, the Subscriber, listens for these events and updates the UI accordingly. Therefore, even though both components manage their own instances, they are not completely independent - the sharing of accurate health data requires this Publisher-Subscriber relationship for effective communication.