Skip to main content
Version: v3

GSIBase

Important Attention Reminder

Coding Style wiki


GSIBase is the abstract base class for game stages in GSIFrame (Game Stage Integration). Each game stage (such as startup, logo, hotfix, login, or lobby) is implemented as a subclass of GSIBase, following the complete OnCreate → OnEnter → OnUpdate → OnExit stage lifecycle. Stages are registered, switched, and driven by a GSIManagerBase subclass.

NamespaceOxGFrame.GSIFrame
Typepublic abstract class
SourceGSIBase.cs
using OxGFrame.GSIFrame;

Declaration

public abstract class GSIBase

After inheriting from GSIBase, you must implement the four lifecycle methods OnCreate, OnEnter, OnUpdate, and OnExit (all abstract).

Lifecycle & Call Sequence

All lifecycle methods are invoked automatically by the manager (a GSIManagerBase subclass) during stage switching and update driving — you never call them yourself. When the manager switches to this stage, the internal initialization flow runs in the following order:

  1. First-time check: if the stage has never been initialized, await OnCreate first (executed only once in the stage's lifetime).
  2. Step 1: call StopUpdate to pause OnUpdate refreshing.
  3. Step 2: await OnEnter to run the stage's entering logic.
  4. Step 3: call RunUpdate to start OnUpdate refreshing.

After that, on every driven update (DriveUpdate), the manager calls OnUpdate as long as this stage is the current stage and runUpdate is true. When switching away, the manager calls this stage's OnExit before running the next stage's initialization flow.

Reminder Both OnCreate and OnEnter are UniTask async methods, so you can conveniently await asset loading and other async operations inside them; the initialization flow waits for OnEnter to finish before enabling OnUpdate refreshing.

Attention The initialization flow is started in fire-and-forget fashion (Forget()), so it never blocks the manager's driven update.

Inheritance Example

using Cysharp.Threading.Tasks;
using OxGFrame.GSIFrame;
using UnityEngine;

// Custom game stage: inherit GSIBase and override the four lifecycle methods
public class StartupStageExample : GSIBase
{
public async override UniTask OnCreate()
{
// Executed once, the first time this stage is switched to (one-time initialization)
Debug.Log($"StartupStage OnCreate, Id: {this.id}");
}

public async override UniTask OnEnter()
{
// Executed every time this stage is switched to
// You can await async operations such as preloading; OnUpdate starts only after this completes
Debug.Log("StartupStage OnEnter");
}

public override void OnUpdate(float dt = 0.0f)
{
// Executed every frame while the stage is active (driven by the manager)
}

public override void OnExit()
{
// Executed when switching away; clean up the data produced by this stage
Debug.Log("StartupStage OnExit");
}
}

Stage subclasses are registered and switched through a GSIManagerBase subclass:

// Switch to this stage from anywhere via the manager (see GSIManagerBase)
GSIManagerExample.ChangeStage<StartupStageExample>();

Reminder You can quickly create a stage subclass from the template via the Project window context menu: Create → OxGFrame → GSI Frame → Template Scripts → Template GSI.cs (Game Stage).

Member Overview

Properties

PropertyDescription
idStage identifier (assigned automatically by the manager on registration).
runUpdateSwitch that controls whether OnUpdate refreshing runs.

Lifecycle Methods (abstract, must be implemented)

MethodDescription
OnCreateExecuted once the first time the stage is entered (async).
OnEnterExecuted every time the stage is entered (async).
OnUpdateExecuted every frame while the stage is active.
OnExitExecuted when switching away from the stage.

General Methods

MethodDescription
SetIdSets the stage identifier (called automatically by the manager on registration).
RunUpdateStarts OnUpdate refreshing.
StopUpdateStops OnUpdate refreshing.

id

public int id { get; private set; }

Description

The unique identifier of the stage. It is assigned automatically when the stage is registered on the manager: when registering via the generic overloads without an id, it is the type's GetHashCode(); otherwise it is the id you passed in. The property is read-only from outside and can only be changed through SetId.


runUpdate

public bool runUpdate { get; private set; }

Description

Switch that controls whether OnUpdate refreshing runs. Only while it is true does the manager's driven update call this stage's OnUpdate. The property is read-only from outside and can only be changed through RunUpdate / StopUpdate.


OnCreate

public abstract UniTask OnCreate()

Returns

UniTask — an awaitable async operation; the initialization flow awaits its completion before running OnEnter.

Description

Executed the first time the stage is switched to, and only once in the stage's lifetime. Suitable for one-time initialization or asset preloading.

Attention OnCreate runs on the first switch into the stage, not at registration time (AddStage).


OnEnter

public abstract UniTask OnEnter()

Returns

UniTask — an awaitable async operation; the initialization flow awaits its completion before enabling OnUpdate refreshing.

Description

Executed every time the stage is switched to. Handles the stage's entering logic (such as opening UI, playing transition animations, or preloading assets). Before it runs, the initialization flow calls StopUpdate to pause refreshing; once it completes, RunUpdate is called automatically to resume refreshing.


OnUpdate

public abstract void OnUpdate(float dt = 0.0f)

Parameters

ParameterTypeDescription
dtfloatDelta time passed in by the manager's driven update (usually Time.deltaTime).
Default: 0.0f

Description

Per-frame update while the stage is active. Called every frame by the manager's driven update (DriveUpdate) as long as this stage is the current stage and runUpdate is true. Handles the stage's recurring logic (such as timers or flow checks).


OnExit

public abstract void OnExit()

Description

Called by the manager when switching to another stage, before the next stage's initialization flow runs. Use it to clean up the data produced by this stage, close related UI, or stop sounds.


SetId

public void SetId(int id)

Parameters

ParameterTypeDescription
idintStage identifier.

Description

Sets the stage identifier id.

Reminder Called automatically by the manager when the stage is registered (AddStage / AddGameStage); you normally never need to call it yourself.


RunUpdate

public void RunUpdate()

Description

Sets runUpdate to true to start OnUpdate refreshing. The initialization flow calls it automatically after OnEnter completes; you can also call it manually inside the stage to resume refreshing after a pause.


StopUpdate

public void StopUpdate()

Description

Sets runUpdate to false to pause OnUpdate refreshing. You can call it manually inside the stage (for example, to suspend stage updates during a cutscene) and resume later with RunUpdate.