Game.UI.UISystemBootstrapper
Assembly:
Assembly-CSharp
Namespace:
Game.UI
Type:
class
Base:
MonoBehaviour, IUIViewComponent
Summary:
Bootstraps the cohtml / Colossal.UI systems for development. Creates a UIManager, one or two UISystems (regular + optional fatal UI), creates Views from provided URLs, sets up input systems and input bindings, and manages their lifecycle (initialization in Awake, per-frame Update/LateUpdate, and cleanup in OnDestroy). This component is intended for development use (logs a warning on Awake) and expects to run on a GameObject that has a Camera and optionally an AudioSource.
Fields
-
private UIView m_View
Holds the primary UIView produced by the main UISystem. Used to access the underlying cohtml View and Listener. -
private UIView m_FatalView
Holds the UIView used for the fatal/error UI (created only when m_EnableFatalUI is true). -
private UIManager m_UIManager
Manages creation and lifetime of UISystems used by this bootstrapper. -
private UIInputSystem m_UIInputSystem
Input system instance associated with the main UISystem; used to dispatch UI input events. -
private UIInputSystem m_FallbackUIInputSystem
Input system instance associated with the fatal UISystem (if created). -
private InputBindings m_InputBindings
Manages binding game input to JS view bindings; attaches when the view signals ReadyForBindings. -
public bool m_EnableFatalUI
If true, creates a separate UISystem/View for displaying fatal error screens (ErrorPage). -
public string m_Url
URL or path passed to the main UISystem.CreateView — the view to load for normal UI. -
public string m_FatalUrl
URL or path passed to the fatal UISystem.CreateView — the view to load for the fatal UI.
Properties
-
public cohtml.Net.View View { get; }
Returns the underlying cohtml View instance from m_View (m_View.View). Can be null until m_View is created. -
public IUnityViewListener Listener { get; }
Returns the view listener (m_View.Listener) for hooking view lifecycle events. Can be null until m_View is created.
Constructors
public UISystemBootstrapper()
Default MonoBehaviour constructor (no custom initialization beyond field defaults). Initialization happens in Awake.
Methods
private async void Awake()
Initializes the UI stack:- Logs a development warning.
- Caches capabilities (awaits Capabilities.CacheCapabilities()).
- Creates InputManager and UIManager (developerMode true).
- Configures Colossal.UI.UISystem.Settings (resource handler, localization manager if GameManager available, enables debugger).
- Creates main UISystem, adds host location "gameui" and creates the main view from m_Url; enables the view and assigns AudioSource and ReadyForBindings handler.
- Creates primary UIInputSystem and InputBindings.
-
If m_EnableFatalUI is true, configures an ErrorPage, sets fonts/roots/stop code, creates a fatal UISystem using FatalResourceHandler and creates m_FatalView with liveReload. Also creates fallback UI input system.
-
private void Update()
Per-frame update: - Enables/disables m_FatalView based on m_EnableFatalUI.
-
Calls InputManager.instance?.Update(), m_UIManager?.Update(), and m_InputBindings?.Update().
-
private void LateUpdate()
Dispatches input events to UIInputSystems: - m_UIInputSystem?.DispatchInputEvents()
-
m_FallbackUIInputSystem?.DispatchInputEvents()
-
private void OnReadyForBindings()
Handler for m_View.Listener.ReadyForBindings — attaches input bindings to the cohtml View when ready. -
private void OnDestroy()
Cleans up: - Unsubscribes ReadyForBindings.
- Detaches and disposes InputBindings.
- Disposes UIInputSystem(s) and UIManager.
-
Destroys InputManager instance.
-
bool IUIViewComponent.get_enabled()
Explicit interface getter that returns the MonoBehaviour.enabled value.
Usage Example
// Attach this component to a GameObject that has a Camera (and optionally an AudioSource).
var go = new GameObject("UISystemBootstrapper");
go.AddComponent<Camera>();
go.AddComponent<AudioSource>();
var bootstrapper = go.AddComponent<Game.UI.UISystemBootstrapper>();
bootstrapper.m_Url = "gameui://main.html";
bootstrapper.m_FatalUrl = "fatal://error.html";
bootstrapper.m_EnableFatalUI = true;
// On play, Awake() will initialize the UI systems and create the views.
Additional notes: - The component expects cohtml (cohtml.Net), Colossal.UI, and related game systems to be available. - Awake is async; it awaits Capabilities.CacheCapabilities() before creating UI systems. - This class is meant for development usage (enables debugger and logs a warning), and the fatal UI creates a debugger on port 9445 by default.