Game.UI.InGame.UIPolicy
Assembly: Assembly-CSharp.dll
Namespace: Game.UI.InGame
Type: readonly struct
Base: System.ValueType, implements System.IEquatable
Summary:
Represents a single policy entry used by the in-game UI. UIPolicy is an immutable (readonly) value type that carries metadata required to render and serialize a policy item: id, localized name, display priority, icon, associated ECS Entity, active/locked state, UI tag, milestone requirement, and optional slider data (UIPolicySlider). Equality semantics are based on the underlying Entity (two UIPolicy instances are considered equal if they reference the same Entity). The struct exposes a Write method to serialize itself into the UI JSON format expected by the prefab UI system.
Fields
-
private readonly string m_Id
Unique identifier for the policy (string key). -
private readonly string m_LocalizedName
Localized display name used for sorting and UI display. -
private readonly int m_Priority
Priority used for ordering policies within the same milestone. -
private readonly string m_Icon
Path or key to the icon used for the policy. -
private readonly Entity m_Entity
Unity.Entities.Entity associated with this policy; used for requirement checks and identity. Equality is determined by this field. -
private readonly bool m_Locked
Whether the policy is locked (unavailable) in the UI. -
private readonly string m_UITag
UI tag string used by the UI system for categorization/lookup. -
private readonly int m_Milestone
Milestone level required for the policy to become available; used as the primary sort key. -
private readonly bool m_Active
Whether the policy is currently active. -
private readonly bool m_Slider
Whether this policy exposes slider data (i.e., has configurable numeric data). -
private readonly UIPolicySlider m_Data
Slider data payload (only meaningful if m_Slider is true). May be serialized as the "data" property.
Properties
- This struct exposes no public properties. All data is provided via constructor parameters and accessed internally; public behavior is through methods (e.g., Write) and interface implementations.
Constructors
public UIPolicy(string id, string localizedName, int priority, string icon, Entity entity, bool active, bool locked, string uiTag, int milestone, bool slider, UIPolicySlider data)
Initializes a new UIPolicy instance with the provided values.
Parameters: - id: unique identifier/key for the policy. - localizedName: localized display name. - priority: ordering priority (secondary sort key). - icon: icon identifier or path. - entity: associated ECS Entity (used for identity and requirements). - active: whether the policy is active. - locked: whether the policy is locked. - uiTag: UI tag string for lookup/categorization. - milestone: milestone level required for availability (primary sort key). - slider: true if the policy has configurable slider data. - data: UIPolicySlider payload (used when slider is true).
Methods
public void Write(PrefabUISystem prefabUISystem, IJsonWriter writer)
Serializes this UIPolicy to the provided IJsonWriter in the UI prefab format. The method writes a policy typed object and includes the following properties:- id (string)
- icon (string)
- entity (Entity or null if Entity.Null)
- active (bool)
- locked (bool)
- uiTag (string)
- requirements (written via prefabUISystem.BindPrefabRequirements(writer, m_Entity))
- data (either UIPolicySlider or null depending on m_Slider)
Notes: - If m_Entity == Entity.Null, the "entity" property is written as null. - Requirements are delegated to PrefabUISystem so the serialized output contains the prefab-specific requirements for the associated entity.
-
public override int GetHashCode()
Returns a hash code generated from a tuple of (m_Id, m_Icon, m_Entity, m_Active, m_Slider, m_Data). Used for hash-based containers. -
public int CompareTo(UIPolicy other)
Compares this UIPolicy against another for ordering. Sorting behavior:- Primary: m_Milestone (ascending)
- Secondary: m_Priority (ascending)
- Tertiary: m_LocalizedName (ordinal string compare) Returns negative if this precedes other, positive if this follows, zero if equal in sorting terms.
-
public override bool Equals(object obj)
Standard override; returns true if obj is a UIPolicy and Equals(UIPolicy) returns true. -
public bool Equals(UIPolicy other)
Equality implementation for IEquatable. Two UIPolicy instances are considered equal if their m_Entity fields are equal (Entity identity). -
public static bool operator ==(UIPolicy left, UIPolicy right)
Equality operator; forwards to Equals. -
public static bool operator !=(UIPolicy left, UIPolicy right)
Inequality operator; negation of Equals.
Usage Example
// Constructing a UIPolicy and serializing it via a PrefabUISystem and IJsonWriter.
// Assume prefabUISystem and writer are available in the calling context, and
// UIPolicySlider is a valid type with its own serialization behavior.
var sliderData = new UIPolicySlider(/* ... */);
var entity = /* an Entity (could be Entity.Null) */;
var policy = new UIPolicy(
id: "ban-car-traffic",
localizedName: "Ban Cars",
priority: 10,
icon: "Icons/PolicyBanCars",
entity: entity,
active: false,
locked: false,
uiTag: "traffic-policies",
milestone: 2,
slider: true,
data: sliderData
);
// Serialize to UI JSON
policy.Write(prefabUISystem, writer);
Additional notes: - UIPolicy is intended for use by UI systems that build policy lists for display and interaction in the Cities: Skylines 2 UI. The Write method follows the prefab UI JSON convention used by the game's UI pipeline. - Because equality is based solely on the Entity field, two UIPolicy instances with identical ids but different entities will be treated as distinct, and vice versa.