///
/// Base class for a high-level game mode handled by .
/// Modes are plain C# classes (not MonoBehaviours); Enter/Exit/Tick are driven
/// manually by the manager. Derive from this and register an instance in
/// GameModeManager.BuildModes().
///
public abstract class GameMode
{
protected GameModeManager Manager { get; private set; }
/// Human-readable name (shown in logs).
public abstract string DisplayName { get; }
internal void Bind(GameModeManager manager) => Manager = manager;
/// Called once when this mode becomes active.
public virtual void Enter() { }
/// Called once when this mode stops being active.
public virtual void Exit() { }
/// Called every frame while this mode is active.
public virtual void Tick() { }
/// Enables the player component and sets whether it accepts movement input.
protected void SetPlayerControl(bool controlEnabled)
{
if (Manager.Player)
{
Manager.Player.enabled = true;
Manager.Player.ControlEnabled = controlEnabled;
}
}
/// Toggles painting on the mesh painter.
protected void SetPainting(bool on)
{
if (Manager.Painter)
Manager.Painter.PaintingEnabled = on;
}
/// Enables/disables the orbit camera input component. Off while a dedicated camera rig is
/// live: the orbit rig would otherwise keep grabbing the cursor and reading the mouse every frame.
protected void SetOrbitInputEnabled(bool on)
{
if (Manager.CameraInput)
Manager.CameraInput.enabled = on;
}
}