Game.Color
Assembly:
Namespace: Game.Objects
Type: struct
Base: System.ValueType, Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.IEmptySerializable
Summary: Represents a compact color/component identifier used by game objects in Cities: Skylines 2. This struct stores a small color index, a color value, and a flag indicating whether this color is a "sub-color" (variant). It is a Unity ECS component (IComponentData), can be used as a query parameter (IQueryTypeParameter), and supports the game's custom serialization marker (IEmptySerializable).
Fields
-
public byte m_Index
Index of the color palette or slot. Use this to identify which palette or category the color belongs to. -
public byte m_Value
The color value within the indexed palette. Typically represents the selected color entry for the given palette/index. -
public bool m_SubColor
When true, indicates this color is a sub-color (a variant) rather than a primary color. Useful for distinguishing alternate color variants for assets.
Properties
- (none)
This struct exposes its data as public fields rather than properties for compactness and straightforward ECS usage.
Constructors
public Color(byte index, byte value, bool subColor = false)
Creates a new Color component instance. Parameters:- index: the palette/index identifier (m_Index).
- value: the color entry value within the palette (m_Value).
- subColor: optional flag indicating a sub-color/variant (m_SubColor). Defaults to false.
Methods
- (none)
No instance methods are declared. Use standard ECS operations (Add/Set/GetComponentData) to work with this component in entity systems.
Usage Example
using Unity.Entities;
using Game.Objects;
// Create and attach the component to an entity
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = entityManager.CreateEntity(typeof(Game.Objects.Color));
// Set component data (entity must have the component type)
entityManager.SetComponentData(e, new Game.Objects.Color(index: 5, value: 128, subColor: true));
// Read component data
var colorComp = entityManager.GetComponentData<Game.Objects.Color>(e);
byte index = colorComp.m_Index;
byte value = colorComp.m_Value;
bool isSub = colorComp.m_SubColor;
{{ Additional notes: - Name collision: Because this type is named "Color", prefer using the fully qualified name Game.Objects.Color when other common Color types (e.g., UnityEngine.Color or System.Drawing.Color) are in scope. - Storage: The struct is intentionally compact (two bytes + a boolean) for efficient ECS storage and serialization. - Serialization: Implements IEmptySerializable to integrate with Colossal's serialization system used by the game. - Query usage: As IQueryTypeParameter, this type can be used in ECS query type parameters to efficiently filter or access entities that include this component. }}