Defining new components

The first step to using SuperScenes is to create your own Scene Component types, as SuperScenes doesn't come with pre-made components out of the box.

You will, however, find example components as part of the Package Samples in the Package Manager.

Creating a new type

To create a new type, simply create a new class and implement the base abstract class SceneComponent. Then, add any data you need the component to hold.

For instance, a simple component that describes how enemy waves are spawn in a certain scene, could look like this:

public class EnemyWaveData : SceneComponent
{
    public int numberOfEnemies;
    public int difficultyLevel;
}

Scene Components can hold any serializable type, and can hold them in List<T> or arrays.

You can store references to other Scenes, and to any other asset type like ScriptableObjects, Prefabs, etc. You can also store references to components present on Prefabs.

SceneComponent script template

You can easily create a new Scene Component by just right-clicking in the Project view, and choosing Create > SuperScenes > New Scene Component.

Very much like it happens for a regular MonoBehaviour with Start and Update, the script generated will contain a pre-made template for a functioning Scene Component, so you'll get a head-start.

OnSceneLoaded / OnSceneUnloaded

Scene Components can also run logic. For instance:

public class EnemyWaveData : SceneComponent
{
    public AudioManagerSO audioManager;
    public AudioClip backgroundMusicTrack;
    
    public void override OnSceneLoaded()
    {
        audioManager.Play(backgroundMusicTrack);
    }
}

In this example, we override the OnSceneLoaded() method from the SceneComponent base class. When this scene is loaded, the code will execute and the AudioManagerSO ScriptableObject will play the referenced AudioClip.

SceneComponent provides both OnSceneLoaded and OnSceneUnloaded methods.

Last updated