Skip to content

Game.UI.InGame.Int2Property

Assembly:
Assembly-CSharp (typical for game code / mods; actual assembly may vary)

Namespace: Game.UI.InGame

Type:
struct

Base:
IJsonWritable

Summary:
A simple value type used to represent and serialize a two-component integer property (label + 2 integer values) for in-game UI. Instances carry a label identifier, a Unity.Mathematics.int2 value (two ints), optional unit text, sign display flag, and optional icon identifiers. The Write method serializes the data to an IJsonWriter using the JSON type name "Game.UI.Common.Number2Property".


Fields

  • public string labelId
    Identifier for the label text or localization key shown alongside the values.

  • public int2 value
    The two integer components (Unity.Mathematics.int2). Represents the numeric values to display (x and y).

  • public string unit
    Optional unit string appended to the displayed values (for example "m", "km/h", etc.).

  • public bool signed
    Whether the numeric values should be treated/displayed as signed (affects formatting/visuals in UI).

  • public string icon
    Optional icon identifier (resource key) associated with the property label.

  • public string valueIcon
    Optional icon identifier shown next to the value(s).

Properties

  • None. This type exposes plain public fields and does not declare C# properties.

Constructors

  • public Int2Property()
    No explicit constructors are declared in source; the default parameterless constructor is available. Initialize fields using object initializer syntax or by assigning fields directly.

Example:

var prop = new Int2Property {
    labelId = "MY_LABEL",
    value = new int2(5, 10),
    unit = "m",
    signed = false,
    icon = "icon_label",
    valueIcon = "icon_value"
};

Methods

  • public void Write(IJsonWriter writer)
    Serializes the struct to the provided IJsonWriter. The method emits a JSON object using the type identifier "Game.UI.Common.Number2Property" and writes the following properties (in order): "labelId", "value", "unit", "signed", "icon", "valueIcon". The writer is expected to support writing strings, booleans and the int2 type (or a compatible representation).

Notes: - The JSON type name is hard-coded as "Game.UI.Common.Number2Property" — consumers of this JSON must expect that type name. - The method performs no null checks on string fields; ensure you pass non-null strings or the writer can handle nulls. - The int2 value is written via writer.Write(value) — this relies on the IJsonWriter implementation having an overload or converter for Unity.Mathematics.int2 (typically writing an array or object with two numeric components).

Usage Example

using Colossal.UI.Binding;
using Unity.Mathematics;

// Build the property
var prop = new Int2Property {
    labelId = "SPEED_LABEL",
    value = new int2(42, 64),
    unit = "km/h",
    signed = false,
    icon = "ui_icon_speed",
    valueIcon = "ui_icon_value"
};

// Serialize to JSON
IJsonWriter writer = /* obtain or implement IJsonWriter */;
prop.Write(writer);

Additional tips: - Ensure the IJsonWriter you use is compatible with how other UI JSON is produced in the game (especially for serializing int2). - Use localization keys for labelId where applicable so the UI system can resolve localized text.