Game.Prefabs.DistrictOptions
Assembly:
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Prefab component used to specify which district policy/options are provided by this prefab. On initialization it encodes the selected DistrictOption enum values into a bitmask and writes that into the DistrictOptionData component on the created entity. This allows the entity to expose the set of district options it represents at runtime.
Fields
public DistrictOption[] m_Options
Array of DistrictOption enum values configured on the prefab (typically via the inspector). During Initialize these entries are turned into a single bitmask (m_OptionMask) that is written to the entity's DistrictOptionData component.
Properties
- None
Constructors
- Implicit default constructor
The class uses the default parameterless constructor provided by the compiler.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the component types that this prefab will provide to created entities. This implementation adds a ReadWriteentry so that created entities will have a DistrictOptionData component. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
No archetype components are added by this prefab (method intentionally empty). -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is instantiated. Calls base.Initialize(entityManager, entity). If m_Options is not null, it creates a DistrictOptionData instance and sets its m_OptionMask by OR-ing 1 << (int)option for each option in m_Options, then writes that component data to the entity via entityManager.SetComponentData(entity, componentData). Note: this assumes DistrictOption enum values are small enough that (1 << value) fits into a uint; enum values >=32 would not fit into the 32-bit mask and would overflow.
Usage Example
// Example: when this prefab is instantiated by the prefab system, Initialize
// will convert the configured m_Options into a bitmask and store it in the entity.
// Programmatic demonstration (normally handled by the prefab/instantiation system):
DistrictOptions prefab = /* obtained from prefab system */;
prefab.m_Options = new[] { DistrictOption.Parks, DistrictOption.NoSmoking }; // example enum values
// When instantiating:
prefab.Initialize(entityManager, entity);
// After this, the entity will have a DistrictOptionData component whose
// m_OptionMask has bits set corresponding to the configured options.
{{ This prefab is intended to be used as part of Cities: Skylines 2 modding to declare which district-level policies/options a prefab provides. The key behaviors are: // - Declaring the DistrictOptionData component via GetPrefabComponents so entities get the component. // - Encoding the selected DistrictOption enum entries into a 32-bit mask on initialization. // Keep in mind to verify the size of the DistrictOption enum to avoid bit overflow. }}