Game.Prefabs.BuildingOptions
Assembly: Game
Namespace: Game.Prefabs
Type: Class
Base: ComponentBase
Summary:
Component used on building prefabs to define a set of BuildingOption flags (policies/options) that should be applied to the entity when the prefab is converted to an ECS entity. The component gathers the configured BuildingOption enum values and encodes them into the BuildingOptionData component's bitmask during Initialize. The class is exposed in the component menu under "Policies/" and references PolicyPrefab via the ComponentMenu attribute.
Fields
public BuildingOption[] m_Options
An array of BuildingOption enum values configured on the prefab (typically in the inspector). These options are read during Initialize to build the bitmask written into BuildingOptionData.m_OptionMask.
Properties
- (No public properties)
This class does not expose additional public properties. It relies on the public field m_Options for configuration and overrides lifecycle methods from ComponentBase.
Constructors
public BuildingOptions()
Implicit parameterless constructor. No special construction logic is defined in the class; initialization of component data occurs in Initialize when the prefab is converted to an entity.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the runtime component type required by this prefab: ComponentType.ReadWrite(). This declares that entities created from this prefab will include a BuildingOptionData component. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Empty override — no additional archetype components are appended here. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called during prefab-to-entity initialization. Calls base.Initialize, then, if m_Options is not null, constructs a bitmask by OR-ing 1 << (int)option for each option in m_Options into a BuildingOptionData instance and writes it to the entity via entityManager.SetComponentData(entity, componentData). This sets BuildingOptionData.m_OptionMask to represent all selected options.
Additional notes: - The method assumes BuildingOption is an enum where each option maps to a distinct bit position. - The class depends on the existence of BuildingOptionData and its m_OptionMask field (type uint) to store the bitmask. - The ComponentMenu attribute on the class registers it under "Policies/" and links to PolicyPrefab for editor grouping.
Usage Example
// Typical internal behavior already implemented in the component:
// During prefab initialization the component builds a bitmask and writes it to the entity:
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
if (m_Options != null)
{
BuildingOptionData componentData = default;
for (int i = 0; i < m_Options.Length; i++)
{
componentData.m_OptionMask |= (uint)(1 << (int)m_Options[i]);
}
entityManager.SetComponentData(entity, componentData);
}
}
// In the editor, add BuildingOptions to a building prefab and set m_Options to the desired flags.
// After conversion to an entity, the BuildingOptionData component on the entity will contain the combined mask.