Skip to content

Game.Prefabs.EnclosedArea

Assembly:
Game.dll (Game assembly)

Namespace:
Game.Prefabs

Type:
class

Base:
ComponentBase

Summary:
Prefab component that represents an enclosed area (e.g., lot, space, surface) with an associated border lane type and orientation. Adds the runtime EnclosedAreaData component to the prefab entity and ensures the archetype contains SubLane so lane data can be stored. Initializes the EnclosedAreaData in LateInitialize by resolving the lane prefab to its entity and copying the counter-clockwise flag.


Fields

  • public NetLanePrefab m_BorderLaneType
    The NetLanePrefab used for the border of this enclosed area. During LateInitialize the prefab system is asked for the entity corresponding to this lane prefab and that entity is stored in the runtime EnclosedAreaData (m_BorderLanePrefab).

  • public bool m_CounterClockWise
    Determines the winding/orientation of the enclosed area border. This value is copied into EnclosedAreaData.m_CounterClockWise during LateInitialize so runtime systems know whether the border runs counter-clockwise.

Properties

  • (none declared)
    This class does not declare any C# properties. It exposes two public fields and several overridden methods inherited from ComponentBase.

Constructors

  • public EnclosedArea()
    Implicit default constructor. There is no custom constructor logic in the source; initialization is performed in LateInitialize.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds dependencies for the prefab system. This override calls the base implementation and then adds m_BorderLaneType to the dependency list so the lane prefab is available/resolved when this prefab is initialized.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Registers the runtime component type that this prefab provides. Adds ComponentType.ReadWrite() so the prefab entity will get an EnclosedAreaData component at spawn.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Ensures the entity archetype includes data needed for runtime lane data. Adds ComponentType.ReadWrite() so that SubLane storage exists in the archetype.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs runtime initialization after dependencies are available. Implementation:

  • Gets the PrefabSystem from the world: entityManager.World.GetExistingSystemManaged().
  • Constructs EnclosedAreaData and sets:
    • m_BorderLanePrefab = existingSystemManaged.GetEntity(m_BorderLaneType)
    • m_CounterClockWise = m_CounterClockWise (copies the prefab flag)
  • Writes the component to the entity via entityManager.SetComponentData(entity, componentData).

Attributes/metadata: - The class is marked with [ComponentMenu("Areas/", new Type[] { typeof(LotPrefab), typeof(SpacePrefab), typeof(SurfacePrefab) })], making it available under the Areas menu and usable as Lot/Space/Surface prefabs.

Usage Example

// The prefab's LateInitialize already performs the typical setup.
// Example showing what LateInitialize does (same pattern used in the prefab):

public override void LateInitialize(EntityManager entityManager, Entity entity)
{
    base.LateInitialize(entityManager, entity);
    PrefabSystem prefabSystem = entityManager.World.GetExistingSystemManaged<PrefabSystem>();
    EnclosedAreaData data = default(EnclosedAreaData);
    data.m_BorderLanePrefab = prefabSystem.GetEntity(m_BorderLaneType);
    data.m_CounterClockWise = m_CounterClockWise;
    entityManager.SetComponentData(entity, data);
}

Additional notes: - EnclosedArea is intended to be used as a prefab authoring component (configured in the editor). The m_BorderLaneType must be set to a valid NetLanePrefab asset so the runtime entity reference can be resolved. - The class uses Unity.Entities API (EntityManager, ComponentType, Entity) and depends on PrefabSystem to resolve prefab-to-entity mappings. Ensure PrefabSystem is available in the world when this prefab is initialized.