Skip to content

Game.Prefabs.CityOptions

Assembly:
Game (inferred)

Namespace:
Game.Prefabs

Type:
class

Base:
ComponentBase

Summary:
Prefab component that exposes a set of city policy/options (CityOption[]) and writes those selections into the runtime entity as CityOptionData during prefab initialization. The component is annotated with a ComponentMenu attribute so it can be created/assigned in the editor under "Policies/". When initialized it builds a bitmask from the selected CityOption entries and stores that mask into CityOptionData on the provided Entity.


Fields

  • public CityOption[] m_Options
    Array of CityOption values assigned on the prefab. Each entry represents a policy/option that should be enabled for the city when this prefab is instantiated. During Initialize(), these values are converted into a bitmask and stored in the CityOptionData component of the entity.

Properties

  • (none)

Constructors

  • public CityOptions()
    No explicit constructor is defined in the source; the default parameterless constructor is used.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds ComponentType.ReadWrite() to the provided set. This declares that the prefab will provide CityOptionData for the entity created from this prefab.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Empty override — this prefab does not add any additional archetype components at this time.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab is instantiated. If m_Options is not null, constructs a CityOptionData instance and builds its m_OptionMask by OR-ing bits for each CityOption present in m_Options:

  • For each CityOption option: set bit (1 << (int)option) in componentData.m_OptionMask (uint).
  • Finally writes the constructed CityOptionData to the entity using entityManager.SetComponentData(entity, componentData).

Notes: - The bitmask uses the enum integer values of CityOption; ensure enum values are within the range that fits into the mask (uint). - The method calls base.Initialize(entityManager, entity) first, preserving base-class initialization behavior.

Usage Example

// Example: a prefab CityOptions component with two chosen options set in the inspector
// When the prefab is instantiated, Initialize(...) will write a CityOptionData with the corresponding bitmask.

[ComponentMenu("Policies/", new Type[] { typeof(PolicyPrefab) })]
public class CityOptions : ComponentBase
{
    public CityOption[] m_Options;

    public override void GetPrefabComponents(HashSet<ComponentType> components)
    {
        components.Add(ComponentType.ReadWrite<CityOptionData>());
    }

    public override void Initialize(EntityManager entityManager, Entity entity)
    {
        base.Initialize(entityManager, entity);
        if (m_Options != null)
        {
            CityOptionData componentData = default(CityOptionData);
            for (int i = 0; i < m_Options.Length; i++)
            {
                componentData.m_OptionMask |= (uint)(1 << (int)m_Options[i]);
            }
            entityManager.SetComponentData(entity, componentData);
        }
    }
}

Additional tips: - Ensure the CityOption enum definition matches expected bit positions before changing values. - If multiple prefabs or systems modify CityOptionData later, coordinate bit usage to avoid collisions.