Game.CityOptionData
Assembly: Assembly-CSharp (game's main assembly)
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter
Summary:
CityOptionData is a small ECS component used to store per-entity city option flags as a 32-bit bitmask. Each bit in m_OptionMask represents a boolean option/feature for the city/prefab. The struct implements IComponentData so it can be attached to entities and IQueryTypeParameter so it can be used in query/filter contexts in Unity's DOTS/Entities workflows for Cities: Skylines 2 modding.
Fields
public uint m_OptionMask
Stores the option flags as a bitmask. Each bit corresponds to a discrete option (on/off). Use bitwise operations to set, clear, or test options.
Properties
- None. This type exposes a single public field and no properties.
Constructors
- Uses the default value-type constructor provided by C#. Initialize with object initializer syntax:
new CityOptionData { m_OptionMask = 0u }
Methods
- None. This is a plain data container (POD) component. Manipulate its value with standard bitwise operations from systems or other code.
Usage Example
// Define option flags you want to use
[System.Flags]
public enum CityOption : uint
{
None = 0,
AllowParks = 1u << 0,
AllowIndustry = 1u << 1,
EnableTourism = 1u << 2,
// add additional options as needed
}
// Adding the component to an entity
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
var e = em.CreateEntity();
em.AddComponentData(e, new CityOptionData { m_OptionMask = (uint)(CityOption.AllowParks | CityOption.EnableTourism) });
// Reading and testing flags
var data = em.GetComponentData<CityOptionData>(e);
bool hasParks = (data.m_OptionMask & (uint)CityOption.AllowParks) != 0;
// Setting a flag (in a system)
data.m_OptionMask |= (uint)CityOption.AllowIndustry;
em.SetComponentData(e, data);
// Clearing a flag
data.m_OptionMask &= ~(uint)CityOption.EnableTourism;
em.SetComponentData(e, data);
Notes: - Since this component is a simple value type, prefer modifying it inside systems (SystemBase/ComponentSystem) using the EntityManager or ComponentDataFromEntity/Entities.ForEach to avoid race conditions. - Define a stable enum for option bits (as shown) to keep code readable and avoid magic numbers.