Skip to content

Game.Prefabs.Modes.TelecomFacilityMode

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

Type: class

Base: LocalModePrefab

Summary:
TelecomFacilityMode is a LocalModePrefab used to modify runtime data for telecom facility prefabs (TelecomFacility) via their ECS data (TelecomFacilityData). It holds an array of ModeData entries that reference PrefabBase instances and multipliers for range and network capacity. At runtime it resolves the prefab's entity (via PrefabSystem) and updates the TelecomFacilityData component on that entity, or restores the original values from the MonoBehaviour component. It also performs a validation pass (RecordChanges) to ensure referenced targets exist and that the ECS component can be read.


Fields

  • public ModeData[] m_ModeDatas
    An array of ModeData entries. Each entry references a PrefabBase (m_Prefab) and two multipliers used when applying the mode. This is public so it can be edited in the inspector.

  • public class ModeData

  • public PrefabBase m_Prefab
    Prefab reference whose TelecomFacility component and entity will be modified.
  • public float m_RangeMultiplier
    Multiplier applied to the TelecomFacilityData.m_Range value when ApplyModeData is executed.
  • public float m_NetworkCapacityMultiplier
    Multiplier applied to the TelecomFacilityData.m_NetworkCapacity value when ApplyModeData is executed.

ModeData groups the prefab target with the multipliers that define the mode behavior.

Properties

  • None (no public properties defined on TelecomFacilityMode itself)

Constructors

  • public TelecomFacilityMode()
    Default parameterless constructor (implicit). No custom initialization in source.

Methods

  • public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
    Validates and touches the ECS component for each referenced prefab. For each ModeData entry it:
  • Gets the TelecomFacility MonoBehaviour from the referenced PrefabBase.
  • If missing, logs a critical message via ComponentBase.baseLog and continues.
  • Resolves the runtime Entity for the prefab using prefabSystem.GetEntity(component.prefab).
  • Calls entityManager.GetComponentData(entity) — this reads the component (likely to ensure it exists / is registered with any change-tracking system). Note that GetComponentData will throw if the component is missing on the entity; the code assumes the entity has the TelecomFacilityData component.

  • public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
    Applies the configured multipliers to the runtime TelecomFacilityData on each resolved entity. For each ModeData:

  • Resolves the TelecomFacility MonoBehaviour and the corresponding Entity.
  • Reads the current TelecomFacilityData from the entity.
  • Sets componentData.m_Range = (int)(componentData.m_Range * modeData.m_RangeMultiplier);
  • Sets componentData.m_NetworkCapacity = (int)(componentData.m_NetworkCapacity * modeData.m_NetworkCapacityMultiplier);
  • Writes the modified component back with entityManager.SetComponentData(entity, componentData). Note: multipliers are floats but values are cast to int, so fractional results are truncated.

  • public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
    Restores the default values by copying them from the MonoBehaviour (TelecomFacility) into the entity's TelecomFacilityData. For each ModeData:

  • Resolves the TelecomFacility MonoBehaviour and the corresponding Entity.
  • Reads the TelecomFacilityData from the entity.
  • Sets componentData.m_Range = component.m_Range;
  • Sets componentData.m_NetworkCapacity = component.m_NetworkCapacity;
  • Writes the modified component back with entityManager.SetComponentData(entity, componentData). This ensures the runtime ECS data matches the original prefab defaults.

Notes and implementation details: - If a referenced PrefabBase does not contain a TelecomFacility component, a critical log is emitted and that entry is skipped. - ApplyModeData uses integer casts which truncate; if you need rounding, perform it explicitly before assigning. - These methods operate on EntityManager and PrefabSystem; they are intended to run at mode application time within the game's prefab/mode system. - The code expects the entity returned by prefabSystem.GetEntity to have a TelecomFacilityData component; otherwise GetComponentData will throw exceptions.

Usage Example

// Example: programmatically set up one ModeData entry on a TelecomFacilityMode instance
public class ExampleSetup
{
    public void Configure(TelecomFacilityMode mode, PrefabBase prefab)
    {
        var md = new TelecomFacilityMode.ModeData
        {
            m_Prefab = prefab,
            m_RangeMultiplier = 1.25f,          // increase range by 25%
            m_NetworkCapacityMultiplier = 0.75f // reduce capacity to 75%
        };
        mode.m_ModeDatas = new[] { md };
    }
}

This class is intended to be edited via the Unity inspector (assign PrefabBase references and multipliers), and the mode system will call RecordChanges, ApplyModeData and RestoreDefaultData at the appropriate times.