Skip to content

Game.Prefabs.RouteOptions

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
RouteOptions is a prefab component used to expose route-related options on a prefab. It stores a serializable array of RouteOption enum values (m_Options) and, during prefab initialization, encodes those options into a bitmask and writes that bitmask into the ECS component RouteOptionData on the entity. The class also declares which ECS component the prefab requires via GetPrefabComponents. This is used by the game's prefab → ECS conversion pipeline to ensure entities have the appropriate component and data at spawn.


Fields

  • public RouteOption[] m_Options
    This array holds the route options chosen on the prefab (typically set in the editor). Each entry is a RouteOption (from Game.Routes). During initialization, the array entries are combined into a single uint bitmask and stored into RouteOptionData.m_OptionMask.

Properties

  • None declared in this class.

Constructors

  • public RouteOptions()
    Default public constructor (implicit). The class relies on Unity/serialization to populate m_Options; no custom construction logic is present.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the required ECS component type for prefabs to the provided set. Specifically, this implementation adds ComponentType.ReadWrite(), signaling that entities created from this prefab need a writable RouteOptionData component.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    No archetype components are added here (method intentionally empty). The prefab does not add additional components to the archetype beyond what GetPrefabComponents specifies.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called during prefab → entity initialization. Implementation details:

  • Calls base.Initialize(entityManager, entity).
  • If m_Options is non-null, constructs a RouteOptionData instance and sets its m_OptionMask by iterating m_Options and OR-ing (1 << (int)option) for each option.
  • Writes the RouteOptionData to the entity using entityManager.SetComponentData(entity, componentData). This effectively encodes selected RouteOption enum values into a single uint mask on the entity.

Usage Example

// Example: a prefab component that has two options set in the inspector.
// When the prefab is converted to an entity, Initialize will pack these into RouteOptionData.m_OptionMask.

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

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

Notes: - RouteOption is expected to be an enum (Game.Routes) where each value corresponds to a bit position in the mask. - RouteOptionData is an ECS component struct with a uint m_OptionMask field; ensure the ECS component exists and is used by systems that read these route options.