Skip to content

Game.UI.InGame.InfoviewUISystemBase

Assembly:
Assembly-CSharp (typical for Cities: Skylines 2 mods; actual assembly may vary)
Namespace: Game.UI.InGame

Type:
abstract class

Base:
UISystemBase, IPreDeserialize

Summary:
Base class for in-game "infoview" UI systems. It provides a simple update gating mechanism using a UIUpdateState to avoid updating every frame unless necessary, a flag to force or request updates (m_Clear / RequestUpdate), and a small set of lifecycle hooks. Derived classes are expected to implement PerformUpdate to refresh the UI contents. Several members are decorated with [Preserve] to ensure they aren't stripped by Unity's managed code stripping.


Fields

  • private UIUpdateState m_UpdateState
    Holds the UIUpdateState instance used to drive periodic updates. The state is created in OnCreate with a default capacity (256 in the original implementation). UIUpdateState.Advance() is used each update to determine if an automatic update should occur; UIUpdateState.ForceUpdate() forces an update.

  • private bool m_Clear
    Flag used to mark the system as "active" (see Active property). Set to true by PreDeserialize and by external code to force that the next OnUpdate should run PerformUpdate. After PerformUpdate runs, the flag is cleared (set to false).

Properties

  • public override GameMode gameMode { get; }
    Always returns GameMode.Game. This indicates that the UI system is active in the main game mode.

  • protected virtual bool Active { get; }
    Default implementation returns the m_Clear flag. Derived classes can override to change activation logic (for example, to consider additional conditions).

  • protected virtual bool Modified { get; }
    Default implementation returns false. Derived classes can override to indicate that data/state has changed and an immediate update is required (used together with UIUpdateState to decide whether to call PerformUpdate).

Constructors

  • protected InfoviewUISystemBase()
    Protected parameterless constructor. Marked with [Preserve] in the source to avoid stripping.

Methods

  • protected void ResetResults<T>(NativeArray<T> results) where T : struct
    Utility to reset a NativeArray by setting every element to default(T). Useful for clearing result buffers before refilling them.

  • [Preserve] protected override void OnCreate()
    Initializes m_UpdateState via UIUpdateState.Create(base.World, 256) and performs base.OnCreate(). Called during the system creation lifecycle.

  • [Preserve] protected override void OnUpdate()
    Called each frame. If the system is Active and either Modified is true or m_UpdateState.Advance() returns true, PerformUpdate() is invoked and m_Clear is set to false. Also calls base.OnUpdate(). This implements the gated update behavior.

  • protected abstract void PerformUpdate()
    Abstract method that derived classes must implement to update the UI (refresh elements, recompute information, etc.). Called only when updates are needed according to Active/Modified/UpdateState.

  • public void RequestUpdate()
    Public helper that calls m_UpdateState.ForceUpdate(), causing the next OnUpdate check to consider the system ready to update (regardless of the period).

  • public void PreDeserialize(Context context)
    Implements IPreDeserialize. Sets m_Clear = true and forces an update via m_UpdateState.ForceUpdate() so that after deserialization the infoview will be refreshed and in a consistent state.

Usage Example

// Example derived infoview system
public class MyInfoviewSystem : InfoviewUISystemBase
{
    private NativeArray<int> m_Results;

    [Preserve]
    protected override void OnCreate()
    {
        base.OnCreate();
        m_Results = new NativeArray<int>(128, Allocator.Persistent);
    }

    protected override bool Modified => /* detect if underlying data changed */ false;

    protected override void PerformUpdate()
    {
        // Clear previous results
        ResetResults(m_Results);

        // ... fill m_Results with current data ...

        // Update UI elements based on m_Results
    }

    protected override void OnDestroy()
    {
        if (m_Results.IsCreated) m_Results.Dispose();
        base.OnDestroy();
    }

    // Somewhere else, when you need to force an update:
    public void ExternalChangeHappened()
    {
        RequestUpdate();
    }
}

Notes and tips: - Override Modified to signal that an immediate update is necessary without waiting for the UIUpdateState timer. - Use RequestUpdate() to force the next frame (or the next OnUpdate cycle) to perform an update. - PreDeserialize ensures the UI refreshes after loading/saving; do not remove unless you handle deserialization elsewhere. - ResetResults is a simple helper for NativeArray clearing; prefer it over manual loops sprinkled across derived classes for consistency.