Game.Areas.District
Assembly:
Assembly-CSharp
Namespace:
Game.Areas
Type:
struct
Base:
System.ValueType, Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary:
Represents a lightweight ECS component that stores a district option bitmask. This struct is intended for use with Unity's Entities (DOTS) in Cities: Skylines 2 modding. It implements ISerializable so its single field can be written to and read from the game's serialization system (saves/loads). The bitmask encodes district options/flags used by the game or mods — treat individual bits as feature flags rather than separate boolean fields.
Fields
public uint m_OptionMask
Stores the district option flags as an unsigned 32-bit bitmask. Each bit represents an on/off option for the district (engine- or mod-defined). Default value is 0 when the struct is default-constructed. When modifying, set, clear and test bits with bitwise operators.
Properties
- (none)
This struct exposes no properties; use the public field m_OptionMask directly.
Constructors
public District()
Default value-type constructor. When created with the default constructor, m_OptionMask is zero. You can create instances using object initializer syntax to set specific flags: new District { m_OptionMask = 0x1u };
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component's state to the provided writer. Implementation writes the single uint m_OptionMask. Used by the game's serialization framework to save this component as part of entity data. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component's state from the provided reader. Implementation reads a uint into m_OptionMask. Used by the game's serialization framework to restore this component on load.
Usage Example
// Add or set the District component on an entity with a specific option mask
var district = new District { m_OptionMask = 0x0001u }; // set bit 0
entityManager.AddComponentData(entity, district);
// Modify individual bits
uint mask = district.m_OptionMask;
mask |= (1u << 2); // set bit 2
mask &= ~(1u << 0); // clear bit 0
district.m_OptionMask = mask;
entityManager.SetComponentData(entity, district);
// Serialize / Deserialize usage (framework calls these during save/load):
// writer and reader are provided by the serialization system; you typically do not call directly.
district.Serialize(writer);
district.Deserialize(reader);
Notes and tips: - Treat m_OptionMask as a compact representation for many boolean options; document which bit corresponds to which option in your mod to avoid conflicts. - Because this is an IComponentData struct, prefer value semantics and avoid heavy instance methods; keep it small and POD-like for performance with ECS. - The Serialize/Deserialize methods rely on the IWriter/IReader implementations provided by the game's save system — ensure compatibility when creating custom writers/readers.