Game.UI.InGame.UITransportType
Assembly:
Game
Namespace:
Game.UI.InGame
Type:
public readonly struct UITransportType
Base:
System.ValueType
Summary:
A lightweight, immutable value-type used by the in-game prefab UI to describe a transport prefab entry. It holds a reference to the prefab Entity and basic metadata (id, icon, locked) and provides a Write method to serialize the entry (including prefab requirements) into a JSON writer via PrefabUISystem.
Fields
private readonly Unity.Entities.Entity m_Prefab
Holds the ECS Entity that represents the prefab for this transport type. This field is used when serializing the prefab's requirements via PrefabUISystem.BindPrefabRequirements. The field is readonly to preserve immutability of the struct.
Properties
-
public string id { get; }
Identifier for this transport type (e.g., internal prefab id or UI id). Read-only. -
public string icon { get; }
Icon name or resource identifier used by the UI for this transport type. Read-only. -
public bool locked { get; }
Flag indicating whether the transport option is locked (true) or available (false). Read-only.
Constructors
public UITransportType(Unity.Entities.Entity prefab, string id, string icon, bool locked)
Creates a new UITransportType instance.- prefab: ECS Entity reference for the transport prefab.
- id: identifier string.
- icon: icon identifier string.
- locked: locked state.
Methods
public void Write(PrefabUISystem prefabUISystem, IJsonWriter writer) : System.Void
Serializes this UITransportType to the provided IJsonWriter. The method:- Begins a typed JSON object using the runtime full type name (GetType().FullName).
- Writes the "id", "icon", and "locked" properties.
- Invokes prefabUISystem.BindPrefabRequirements(writer, m_Prefab) to write the prefab's requirements (so the client/UI can know prerequisite info).
- Ends the typed JSON object.
This method expects valid PrefabUISystem and IJsonWriter instances; it does not modify the struct state.
Usage Example
using Unity.Entities;
using Colossal.UI.Binding;
using Game.UI.InGame;
// Example usage in code that has access to a PrefabUISystem and an IJsonWriter:
void SerializeTransportEntry(PrefabUISystem prefabUISystem, IJsonWriter writer, Entity prefabEntity)
{
var transport = new UITransportType(prefabEntity, "metro_line", "icon_metro", locked: false);
transport.Write(prefabUISystem, writer);
}
Notes and remarks: - The struct is immutable after construction. - The m_Prefab Entity is not directly serialized as a raw entity; instead PrefabUISystem.BindPrefabRequirements is used to serialize relevant requirement data for the prefab. - This type is intended for use within Cities: Skylines 2 modding/UI code where PrefabUISystem and IJsonWriter implementations are available.