Skip to content

Game.Prefabs.Modes.PrisonMode

Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes

Type: class

Base: LocalModePrefab

Summary:
PrisonMode is a prefab component used to apply "mode" adjustments to prison prefabs in the game. It holds an array of ModeData entries that reference individual prison prefabs and mode-specific overrides. At runtime the class can: - Ensure components exist on the entity (RecordChanges), - Apply scaled or overridden values to the PrisonData component (ApplyModeData), - Restore the PrisonData values to the defaults defined on the original Prison prefab (RestoreDefaultData).

It logs a critical message and skips any ModeData entry whose referenced Prefab does not expose a Prison component.


Fields

  • public ModeData[] m_ModeDatas
    An array of ModeData entries. Each entry refers to a prefab (PrefabBase) and the mode-specific values to apply to that prefab's PrisonData (capacity multiplier, prisoner wellbeing, prisoner health). If empty, no prefabs are affected.

Nested type ModeData fields (inner class): - public PrefabBase m_Prefab
Reference to the target prefab whose Prison component/data will be modified. - public float m_PrisonVanCapacityMultiplier
Multiplier applied to the existing PrisonData.m_PrisonVanCapacity when ApplyModeData runs. - public sbyte m_PrisonerWellbeing
New value to set for PrisonData.m_PrisonerWellbeing when ApplyModeData runs. - public sbyte m_PrisonerHealth
New value to set for PrisonData.m_PrisonerHealth when ApplyModeData runs.

Notes: - If the referenced prefab does not contain a Prison component, the entry is skipped and a critical log is emitted via ComponentBase.baseLog.Critical. - m_ModeDatas is intended to be configured in the prefab (inspector) for the mode asset.

Properties

  • None declared directly on PrisonMode. (It inherits whatever properties LocalModePrefab provides.)

Constructors

  • public PrisonMode()
    Default parameterless constructor (implicit if not defined). The component is intended to be used as a prefab component; initialization is typically handled by the prefab system and Unity serialization.

Methods

  • public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
    Loops through m_ModeDatas; for each entry it:
  • Retrieves the Prison component from the referenced PrefabBase.
  • If missing, logs and continues.
  • Uses prefabSystem.GetEntity(component.prefab) to find the ECS entity for the prefab.
  • Calls entityManager.GetComponentData(entity) — this read appears intended to ensure the component exists / record current data state so the prefab system tracks the component (no modification is performed here).

  • public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
    Applies mode overrides to each listed prefab:

  • For each ModeData, retrieves the Prison component from the referenced prefab.
  • If missing, logs and continues.
  • Gets the entity for the prefab and reads its PrisonData.
  • Multiplies the existing m_PrisonVanCapacity by m_PrisonVanCapacityMultiplier and assigns it back (casts to int).
  • Sets m_PrisonerWellbeing and m_PrisonerHealth to the values provided by ModeData.
  • Writes the modified PrisonData back to the entity with entityManager.SetComponentData.

  • public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
    Restores PrisonData fields to the defaults defined by the referenced Prison component on the prefab:

  • For each entry, retrieves the Prison component; if missing, logs and continues.
  • Reads the current PrisonData from the entity.
  • Assigns m_PrisonVanCapacity, m_PrisonerWellbeing, and m_PrisonerHealth from the values defined on the Prison component (component.m_PrisonVanCapacity, component.m_PrisonerWellbeing, component.m_PrisonerHealth).
  • Writes the restored PrisonData back to the entity.

General notes on methods: - All methods accept an EntityManager and PrefabSystem; these are required to resolve prefab ECS entities and to read/write component data. - Methods rely on the Prison component being present on the referenced PrefabBase; otherwise the entry is skipped. - Logging uses ComponentBase.baseLog.Critical to report missing targets.

Usage Example

// Example: applying a mode at runtime (simplified)
PrisonMode prisonMode = /* obtain reference to the PrisonMode prefab component */;
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
PrefabSystem prefabSystem = /* obtain reference to PrefabSystem */;

// Ensure components are registered / record current values
prisonMode.RecordChanges(entityManager, prefabSystem);

// Apply the mode changes configured in m_ModeDatas
prisonMode.ApplyModeData(entityManager, prefabSystem);

// Later, to restore defaults:
prisonMode.RestoreDefaultData(entityManager, prefabSystem);

Additional tips: - Configure m_ModeDatas in the prefab inspector with correct PrefabBase references. - Ensure PrefabSystem and EntityManager used here correspond to the game's conversion/runtime world where prefabs are instantiated. - Be mindful that ApplyModeData multiplies the current capacity; calling it multiple times without restoring defaults will repeatedly multiply unless handled externally.