If you need to override a transition while it is in progress (e.g., an event scene detects it is no longer valid during OnInitialize), you can call a navigation method like Pop or Push from the GlobalSceneNavigator.Instance.
When a new transition is initiated, Navigathena cancels the CancellationTokenSource managed by the SceneNavigator. This causes the CancellationToken passed into the current lifecycle events (like OnInitialize) to enter a canceled state. Subsequent lifecycle methods, such as OnEnter, will not be called if the transition is interrupted.
protected override async UniTask OnInitialize (ISceneDataReader reader, IProgress<IProgressDataStore> progress, CancellationToken cancellationToken)
{
// Assume the event has expired.
bool isExpired = true;
if (isExpired) {
// NOTE: The cancellationToken is not passed to the transition operation because the cancellation state is canceled when the transition operation is performed.
await GlobalSceneNavigator.Instance.Pop(CancellationToken.None);
// cancellationToken.IsCancellationRequested will be true
Debug.Log(cancellationToken.IsCancellationRequested);
}
}
protected override UniTask OnEnter (ISceneDataReader reader, CancellationToken cancellationToken)
{
// This will not be called if Pop was called in OnInitialize
Debug.Log("EventSceneEntryPoint.OnEnter");
return UniTask.CompletedTask;
}