<aside> <img src="/icons/reorder_gray.svg" alt="/icons/reorder_gray.svg" width="40px" />
Navigation
</aside>
<aside> 💡 Three interfaces connect level objects with the run: IChunkActivatable turns objects on near the character, IRunStateObject resets objects after a run and ISceneSaveObject stores the data of one level.
</aside>
public interface IChunkActivatable
{
void OnChunkActivated();
void OnChunkDeactivated();
}
LevelSceneController splits the level into chunks along the world Z axis (default 20 m). When the character moves to a new chunk, the objects of the chunks within Active Chunk Radius receive OnChunkActivated and the objects of the other chunks receive OnChunkDeactivated.
The callbacks toggle behaviours (animation, effects, registration in a controller), not the GameObject.
| Object | What the chunk does |
|---|---|
BoostRamp |
Runs the arrow animation only while active. |
BreakablePropBehavior |
Registers in BreakablePropController only while active. |
CoinPickup, GemPickup, BoosterCubeBehavior |
Animates only while active. |
The chunks are baked when the level scene is saved. After adding an object that implements IChunkActivatable, save the level scene.
public interface IRunStateObject
{
void ResetState();
}
Objects with temporary state, such as breakable props, run coins and one-shot triggers, call RunStateController.MarkDirty(this) when the state changes. GameController calls RunStateController.ResetRun() in PrepareRun.
MarkDirty from its own ResetState to be reset again on the next run, as BoosterSpawner does.public interface ISceneSaveObject
{
void InitSave(string levelId);
}
Implemented by objects whose save data belongs to one Level, such as Pickup and RecordWall. One scene can be reused by several Level assets, so the objects namespace their save keys with the level id.
| Owner | Called for |
|---|---|
LevelSceneController |
Every object in the level scene. |
GameController |
Objects of the Game scene, such as RecordWall. |
using UnityEngine;
namespace Watermelon
{
public class MovingGate : MonoBehaviour, IRunStateObject
{
private Vector3 startPosition;
private void Awake()
{
startPosition = transform.position;
}
public void Open()
{
transform.position += Vector3.up * 5f;
RunStateController.MarkDirty(this);
}
public void ResetState()
{
transform.position = startPosition;
}
}
}
The save data is explained in Save Data.