Game.Prefabs.ZoneBlockPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: PrefabBase
Summary:
ZoneBlockPrefab is a prefab type used by the game to represent a zoned block (a block of tiles belonging to a specific zone type). It exposes a material and a reference to a ZonePrefab (the zone type). The class contributes required component types for the prefab and constructs an EntityArchetype for instantiated zone block entities during LateInitialize, storing it in the ZoneBlockData component on the prefab entity. This setup integrates with the Unity.Entities (ECS) pipeline used by the game.
Fields
-
public UnityEngine.Material m_Material
Material used for rendering the zone block. Can be assigned in the prefab to control visual appearance. -
public ZonePrefab m_ZoneType
Reference to the ZonePrefab that defines the specific zone type (e.g., residential, commercial) this block represents. Added as a dependency so the zone prefab is available when building scenes/entities.
Properties
- None specific to this class. All behavior is provided via overridden methods from PrefabBase and data written into ECS components.
Constructors
public ZoneBlockPrefab()
Default constructor (implicit). Prefab classes are typically constructed by Unity when loading prefabs; no custom construction logic is defined here.
Methods
-
public override void GetDependencies(List<PrefabBase> prefabs)
Adds dependent prefabs required by this prefab. Implementation calls base.GetDependencies(prefabs) and then addsm_ZoneType
so the zone prefab is included in the dependency list. -
public override void GetPrefabComponents(HashSet<ComponentType> components)
Registers component types that the prefab entity requires. This implementation adds: ZoneBlockData
(read/write)-
BatchGroup
(read/write) in addition to any components registered by the base class. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Registers components that should belong to the archetype used for instantiated zone block entities. This implementation adds: CurvePosition
ValidArea
BuildOrder
Cell
CullingInfo
-
MeshBatch
All are added as ReadWrite ComponentType entries in addition to base class entries. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Builds and stores an EntityArchetype for runtime zone block entities. Behavior: - Calls the base LateInitialize.
- Collects components from attached ComponentBase instances (
GetComponents(list)
), and accumulates their archetype component requirements by calling each component's GetArchetypeComponents. - Ensures
Block
,Created
, andUpdated
component types are present. - Creates an archetype via
entityManager.CreateArchetype()
using the combined component set and writes it intoZoneBlockData.m_Archetype
on the prefab entity. This archetype is later used when creating actual zone block entities at runtime.
Usage Example
// After the prefab's LateInitialize has run, you can read the generated archetype:
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
ZoneBlockData data = em.GetComponentData<ZoneBlockData>(prefabEntity);
EntityArchetype zoneBlockArchetype = data.m_Archetype;
// You can then create instances (zone blocks) using that archetype:
Entity newZoneBlock = em.CreateEntity(zoneBlockArchetype);
// set required component data on newZoneBlock as appropriate...
{{ Additional notes: - ZoneBlockPrefab works within the game's ECS-based prefab system. It does not itself implement rendering or building logic; instead it defines the components and archetype that other systems use to process, render, and manage zone blocks. - m_Material and m_ZoneType are intended to be set in the prefab authoring (Inspector) so dependent systems and rendering can use them. - The LateInitialize method relies on PrefabUtils.ToArray(hashSet) to convert the component set into an array acceptable to CreateArchetype. }}