Game.Prefabs.AreaPrefab
Assembly:
Game
Namespace:
Game.Prefabs
Type:
class
Base:
PrefabBase
Summary:
Represents a prefab asset for areas (polygons) used by the game. Exposes color fields for visual appearance and is responsible for declaring which ECS components and archetype components should be present on entities instantiated from this prefab. During LateInitialize it composes an EntityArchetype for area instances (including components contributed by child components) and stores it on the AreaData component.
Fields
-
public UnityEngine.Color m_Color
Main fill color used for the area. Serialized and editable on the prefab. -
public UnityEngine.Color m_EdgeColor
Color used for the area edges. -
public UnityEngine.Color m_SelectionColor
Fill color used when the area is selected. -
public UnityEngine.Color m_SelectionEdgeColor
Edge color used when the area is selected.
Properties
- This class does not declare any properties.
Constructors
public AreaPrefab()
Default parameterless constructor (inherited behavior). The prefab is typically configured in the Unity editor; no custom constructor logic is present in this class.
Methods
public override void GetPrefabComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
Adds the runtime ECS components that should be attached to the prefab entity itself. Calls base implementation then adds:- AreaData (ReadWrite)
- AreaColorData (ReadWrite)
-
PlaceableInfoviewItem (ReadWrite) Purpose: ensures prefab entity contains the data blobs required by area systems and UI.
-
public override void GetArchetypeComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
Adds the components that will be part of the archetype for area instances. Calls base implementation then adds: - Node (ReadWrite)
-
Triangle (ReadWrite) Purpose: declares the structural components used by area geometry on instantiated entities.
-
public override void LateInitialize(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity entity)
Performs additional setup after the prefab is created. Behavior: - Calls base.LateInitialize.
- Collects child ComponentBase-derived components via GetComponents(list).
- Starts a HashSet of ComponentType and adds Area (ReadWrite).
- For each collected child component, calls their GetArchetypeComponents to let them contribute component types.
- Adds Created and Updated component types.
- Reads AreaData from the prefab entity, creates an EntityArchetype from the accumulated component set, assigns it to AreaData.m_Archetype, and writes AreaData back to the entity. Purpose: builds and stores the concrete archetype used to create runtime area entities that include all components contributed by nested components and required structural types.
Usage Example
// Example: In editor, configure an AreaPrefab asset's colors.
// At runtime, when the prefab entity is initialized, LateInitialize will compose
// an archetype containing Area, Node, Triangle, Created, Updated and any
// additional components provided by nested components, and store it on AreaData.
AreaPrefab prefab = /* obtain prefab asset */;
EntityManager em = /* obtain EntityManager */;
Entity prefabEntity = /* entity representing the prefab */;
// LateInitialize will create the archetype and write it into the prefab's AreaData.
prefab.LateInitialize(em, prefabEntity);
// Later, systems can instantiate area entities using the archetype stored in AreaData.