Skip to content

Game.SceneFlow.LoadingScreen

Assembly:
Assembly-CSharp (game runtime assembly)

Namespace:
Game.SceneFlow

Type:
class

Base:
IScreenState

Summary:
LoadingScreen is an IScreenState implementation that drives the game's loading overlay UI while background tasks run. It activates an overlay screen and an input overlay barrier, repeatedly polls the TaskManager for progress of three progress groups, updates the overlay progress indicators (outer, middle, inner), and awaits between polls. The method honors cancellation via the supplied CancellationToken and ensures progress indicators are set to 100% before allowing the overlay to finish. Internally it uses InputManager.instance.CreateOverlayBarrier to block input and OverlayBindings to control the overlay UI.


Fields

  • This type declares no instance or static fields.
    The class only contains an async method and a private local static helper; no fields are stored on the instance.

Properties

  • This type declares no properties.

Constructors

  • public LoadingScreen()
    This constructor is the default parameterless constructor generated by the compiler. The class does not declare an explicit constructor.

Methods

  • public async Task Execute(GameManager manager, CancellationToken token)
    Executes the loading-screen flow. Behavior summary:
  • Obtains OverlayBindings from manager.userInterface.overlayBindings.
  • Creates an overlay input barrier via InputManager.instance.CreateOverlayBarrier("LoadingScreen") to block input while loading.
  • Activates the loading overlay screen via overlay.ActivateScreenScoped(OverlayScreen.Loading).
  • Loops while the nested Poll method reports progress groups are not complete:
    • Throws if cancellation was requested (token.ThrowIfCancellationRequested()).
    • Updates overlay progress indicators:
    • OverlayProgressType.Outer <- progress[0]
    • OverlayProgressType.Middle <- progress[1]
    • OverlayProgressType.Inner <- progress[2]
    • Awaits Task.Delay(100, token) between polls.
  • Once polls return completed, sets all three overlay progress values to 1.0f.
  • Performs a short spin of ~30 yields (await Task.Yield repeated) while checking cancellation, to allow the UI to settle before exiting and releasing the overlay barrier.
  • Returns when complete.

  • static bool Poll(float[] array) (private local static method inside Execute)
    Populates the provided float[3] array with current task progress:

  • array[0] = TaskManager.instance.GetTaskProgress(ProgressTracker.Group.Group1)
  • array[1] = TaskManager.instance.GetTaskProgress(ProgressTracker.Group.Group2)
  • array[2] = TaskManager.instance.GetTaskProgress(ProgressTracker.Group.Group3) Returns true if any of the three group progress values are less than 1.0f (i.e., loading still in progress); otherwise returns false.

Notes: - The method depends on global singletons: TaskManager.instance, InputManager.instance, and the manager.userInterface overlay bindings. - Cancellation is cooperative — callers must observe the CancellationToken to abort early. - The overlay input barrier and overlay activation are disposed automatically by using blocks in the method, ensuring input is unblocked and the overlay deactivated when the method completes or is cancelled.

Usage Example

// Typical usage: call from scene manager / flow controller with the game's GameManager instance.
var loadingScreen = new Game.SceneFlow.LoadingScreen();
using var cts = new CancellationTokenSource();

// Await the Execute call; it will manage the overlay and input barrier internally.
await loadingScreen.Execute(gameManager, cts.Token);

This call will show the loading overlay, update its three progress rings based on TaskManager progress groups, and automatically remove the overlay and barrier when loading completes or the token is cancelled.