Skip to content

Game.Prefabs.Modes.EmergencyShelterMode

Assembly:
Namespace: Game.Prefabs.Modes

Type: class

Base: LocalModePrefab

Summary:
EmergencyShelterMode is a prefab mode component used to modify EmergencyShelter-related entity data for one or more prefabs. It contains an array of ModeData entries (each referencing a PrefabBase and mode parameters) and implements three main lifecycle methods: - RecordChanges: ensures the EmergencyShelterData component exists on the target entity (reads it via EntityManager). - ApplyModeData: applies the mode's shelter capacity multiplier and vehicle capacity to EmergencyShelterData on the target entity. - RestoreDefaultData: restores EmergencyShelterData values from the EmergencyShelter prefab's default fields.

The class looks up prefabs via components on the referenced PrefabBase (GroundWaterPowered or EmergencyShelter) and uses a PrefabSystem to map those prefab references to ECS Entity instances. If the expected component is missing on a referenced prefab, the class logs a critical error and skips that entry.

Fields

  • public ModeData[] m_ModeDatas
    Array of ModeData entries describing which prefabs to affect and how (shelter capacity multiplier and vehicle capacity). Each element should reference a PrefabBase and the desired mode values.

Nested class ModeData fields: - public PrefabBase m_Prefab
Reference to the target prefab whose EmergencyShelterData will be modified or restored.

  • public float m_ShelterCapacityMultiplier
    Multiplier applied to the prefab's current EmergencyShelterData.m_ShelterCapacity when ApplyModeData is invoked.

  • public int m_VehicleCapacity
    Vehicle capacity value applied to EmergencyShelterData.m_VehicleCapacity when ApplyModeData is invoked.

Properties

  • (none)

Constructors

  • public EmergencyShelterMode()
    Default constructor (not explicitly declared in source; the compiler-provided default is used). No custom construction logic in the class.

Methods

  • public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
    Iterates m_ModeDatas and for each entry:
  • Retrieves the GroundWaterPowered component from the referenced PrefabBase.
  • If missing, logs a critical error and continues.
  • Uses prefabSystem.GetEntity(component.prefab) to obtain the Entity.
  • Calls entityManager.GetComponentData(entity) to ensure the component exists / to record its presence.

  • public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
    Iterates m_ModeDatas and for each entry:

  • Retrieves the GroundWaterPowered component from the referenced PrefabBase.
  • If missing, logs a critical error and continues.
  • Resolves the Entity via prefabSystem.GetEntity(component.prefab).
  • Reads EmergencyShelterData from the entity, multiplies m_ShelterCapacity by m_ShelterCapacityMultiplier (cast to int), sets m_VehicleCapacity to the ModeData value, then writes the modified EmergencyShelterData back to the entity via entityManager.SetComponentData.

  • public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
    Iterates m_ModeDatas and for each entry:

  • Retrieves the EmergencyShelter component from the referenced PrefabBase.
  • If missing, logs a critical error and continues.
  • Resolves the Entity via prefabSystem.GetEntity(component.prefab).
  • Reads EmergencyShelterData from the entity and replaces m_ShelterCapacity and m_VehicleCapacity with the defaults from the EmergencyShelter prefab instance, then writes the modified EmergencyShelterData back to the entity.

Notes: - Logging is performed through ComponentBase.baseLog.Critical when an expected component (GroundWaterPowered or EmergencyShelter) is missing on the referenced PrefabBase. - The code assumes the types PrefabBase, GroundWaterPowered, EmergencyShelter, EmergencyShelterData, PrefabSystem and ComponentBase exist in the project and behave as implied (prefab references and ECS entity mapping).

Usage Example

// Example: programmatically applying mode data to entities (typically this component
// is configured in the prefab inspector, but this shows the intended runtime use).
EmergencyShelterMode mode = /* obtain from prefab or component */;
EntityManager entityManager = /* obtain from World.DefaultGameObjectInjectionWorld */;
PrefabSystem prefabSystem = /* obtain PrefabSystem instance */;

// Apply the configured mode values to all referenced prefabs/entities
mode.ApplyModeData(entityManager, prefabSystem);

// To restore defaults later
mode.RestoreDefaultData(entityManager, prefabSystem);