Skip to content

Game.UI.InGame.ColorSection

Assembly: Game
Namespace: Game.UI.InGame

Type: class

Base: InfoSectionBase

Summary:
UI info section used in-game to view and change the color of a route/transport line. It exposes a trigger binding ("setColor") that applies a UnityEngine.Color to the selected route entity and its vehicles, creates a small event entity to notify other systems (ColorUpdated), and requests the UI to refresh. The section is visible only when the selected entity has the required route/line components.


Fields

  • private Unity.Entities.EntityArchetype m_ColorUpdateArchetype
    {{ This archetype is created in OnCreate and used to spawn an event entity (ColorUpdated) when the color change is applied. The archetype includes Game.Common.Event and ColorUpdated components so other systems can react to the color update. }}

  • private UnityEngine.Color32 color { get; set; }
    {{ A private Color32 property holding the current color value read from the selected entity during OnProcess and written out by OnWriteProperties. It is reset to default(Color32) in Reset(). }}

Properties

  • private UnityEngine.Color32 color { get; set; }
    {{ This private property stores the current color for the UI section. It is not exposed publicly; it's updated from the entity's Game.Routes.Color component in OnProcess and serialized via OnWriteProperties. }}

Constructors

  • public ColorSection()
    {{ Default constructor. Marked with [Preserve] in the source to avoid stripping by the runtime code stripper. Initialization of archetypes and bindings happens in OnCreate rather than here. }}

Methods

  • protected override string group => "ColorSection"
    {{ Read-only property override that returns the group name used for bindings and UI identification. }}

  • protected override void Reset()
    {{ Resets the internal color to default(Color32). Called by the base lifecycle when the section is reset. }}

  • [Preserve] protected override void OnCreate()
    {{ Called during creation of the section. It registers a TriggerBinding for "setColor" that calls OnSetColor, and creates the m_ColorUpdateArchetype (Event + ColorUpdated) used to signal color changes. Uses base.EntityManager to create the archetype. }}

  • private void OnSetColor(UnityEngine.Color uiColor)
    {{ Callback invoked by the "setColor" binding. Behavior:

  • Verifies the selected entity has Route, TransportLine, RouteWaypoint and Game.Routes.Color components; returns early otherwise.
  • Uses the EndFrameBarrier (from the base) to create an EntityCommandBuffer and sets the Game.Routes.Color on the selectedEntity.
  • If the selected entity has a DynamicBuffer, iterates it and adds the Game.Routes.Color component to each vehicle entity.
  • Creates a new event entity using m_ColorUpdateArchetype and sets a ColorUpdated with the selectedEntity so other systems can respond.
  • Calls m_InfoUISystem.RequestUpdate() to refresh the UI. }}

  • private bool Visible()
    {{ Determines whether the section should be visible. Returns true only if the selected entity has Route, TransportLine, RouteWaypoint and also a Game.Routes.Color component. }}

  • [Preserve] protected override void OnUpdate()
    {{ Updates the section's visibility each frame by setting base.visible = Visible(). Marked Preserve to avoid stripping. }}

  • protected override void OnProcess()
    {{ Reads the Game.Routes.Color component of the selectedEntity and stores its m_Color into the private color property. Called as part of the section processing lifecycle. }}

  • public override void OnWriteProperties(IJsonWriter writer)
    {{ Serializes the current color to the provided JSON writer under the property name "color". This is used when the UI/section state is written out. }}

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Register a trigger binding from UI that will call OnSetColor when the user selects a color.
    AddBinding(new TriggerBinding<UnityEngine.Color>(group, "setColor", OnSetColor));

    // Create an archetype for a small event entity used to notify systems about a color update.
    m_ColorUpdateArchetype = base.EntityManager.CreateArchetype(
        ComponentType.ReadWrite<Game.Common.Event>(),
        ComponentType.ReadWrite<ColorUpdated>()
    );
}