Skip to content

Game.Prefabs.SpawnableBuilding

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: public class

Base: ComponentBase

Summary:
Component that marks a BuildingPrefab as a spawnable building tied to a ZonePrefab. It exposes a zone type reference and a level (1–5) and delegates most of the prefab/component/archetype initialization work to the referred ZonePrefab. It also writes runtime SpawnableBuildingData (including a reference to the zone prefab entity) during LateInitialize so the spawned building entity can be associated with its zone type and configured level.


Fields

  • public ZonePrefab m_ZoneType
    Reference to the ZonePrefab that defines additional components, archetype requirements and initialization for this building. When set, various methods delegate to this ZonePrefab to add prefab components, archetype components and perform building-specific initialization.

  • public byte m_Level
    Building level (constrained by [Range(1f, 5f)]). Passed to the ZonePrefab when requesting components/archetype information and stored into the SpawnableBuildingData component during LateInitialize.

Properties

  • public override bool ignoreUnlockDependencies { get; }
    Always returns true (overrides base). Indicates that unlock dependencies are ignored for this component/prefab (i.e., it will not participate in the usual unlock dependency checks).

  • public override IEnumerable<string> modTags { get; }
    Yields mod tags from the base implementation, and if m_ZoneType contains a UIObject whose m_Group is a UIAssetCategoryPrefab, yields an additional tag in the format "SpawnableBuilding" + uIAssetCategoryPrefab.name. This allows categorizing the prefab by the zone UI category for tooling/filters.

Constructors

  • public SpawnableBuilding()
    Default constructor (no custom construction logic in source).

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds m_ZoneType to the provided dependency list (in addition to base dependencies). Ensures the referenced zone prefab is included as a dependency of the building prefab.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds required prefab-level ComponentType entries:

  • SpawnableBuildingData (ReadWrite)
  • BuildingSpawnGroupData (ReadWrite)
    If m_ZoneType is set, calls m_ZoneType.GetBuildingPrefabComponents(components, (BuildingPrefab)prefab, m_Level) so the zone prefab can add any building-specific prefab components for the given level.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds building archetype-level components:

  • BuildingCondition (ReadWrite)
    If m_ZoneType is set, also:
  • Adds RandomLocalizationIndex (ReadWrite) if the zone type has RandomLocalization.
  • Calls m_ZoneType.GetBuildingArchetypeComponents(components, (BuildingPrefab)prefab, m_Level) to let the zone prefab add any required archetype components based on building level.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Calls base.Initialize and, if m_ZoneType is set, calls m_ZoneType.InitializeBuilding(entityManager, entity, (BuildingPrefab)prefab, m_Level). This lets the zone prefab perform per-entity initialization that must run at the Initialize stage.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs the LateInitialize flow and writes the SpawnableBuildingData component to the entity:

  • Creates a SpawnableBuildingData instance and sets its m_Level from this.m_Level.
  • Uses PrefabSystem (fetched from entityManager.World.GetExistingSystemManaged()) to resolve the entity corresponding to the referenced m_ZoneType and assigns it to componentData.m_ZonePrefab (if m_ZoneType != null).
  • Sets the component data on the entity via entityManager.SetComponentData(entity, componentData).
    This step ensures the runtime entity contains the zone prefab entity reference and configured level for spawn-time logic.

Usage Example

// Example: reading SpawnableBuildingData from a created building entity
SpawnableBuildingData data = entityManager.GetComponentData<SpawnableBuildingData>(buildingEntity);
Entity zonePrefabEntity = data.m_ZonePrefab;
byte buildingLevel = data.m_Level;

// Example: typical prefab setup (in inspector):
// - Add a SpawnableBuilding component to a BuildingPrefab asset.
// - Assign m_ZoneType to the desired ZonePrefab.
// - Set m_Level (1..5).
//
// The game will then:
// - include the zone prefab as a dependency,
// - ask the zone prefab to add prefab/archetype components for the given level,
// - call Initialize/LateInitialize to allow the zone prefab to configure the entity,
// - write the SpawnableBuildingData (level + zone prefab entity) to the building entity.