Skip to content

Game.Prefabs.Modes.ServiceCoverageMode

Assembly: Game
Namespace: Game.Prefabs.Modes

Type: class

Base: LocalModePrefab

Summary:
ServiceCoverageMode is a prefab mode component used to apply configurable coverage parameters (range, capacity, magnitude) to service prefabs that expose a ServiceCoverage component. It holds an array of ModeData entries that reference target prefabs and the values to apply. The component can record required ECS components, apply custom data to entities, and restore defaults from the original ServiceCoverage component on the prefab.


Fields

  • public ModeData[] m_ModeDatas
    Holds an array of ModeData entries. Each entry references a Prefab (PrefabBase) that must contain a ServiceCoverage component and provides the values to write into the entity's CoverageData component.

Nested type ModeData (inner class):

  • public PrefabBase m_Prefab
    Reference to the target prefab with a ServiceCoverage component.

  • public float m_Range
    Custom range value to set on the target prefab's CoverageData when ApplyModeData is called.

  • public float m_Capacity
    Custom capacity value to set on the target prefab's CoverageData when ApplyModeData is called.

  • public float m_Magnitude
    Custom magnitude value to set on the target prefab's CoverageData when ApplyModeData is called.

Properties

  • (None)

Constructors

  • public ServiceCoverageMode()
    Default constructor (implicit). No special initialization present in the source; the component is intended to be configured via the inspector or by setting m_ModeDatas programmatically.

Methods

  • public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
    Iterates all entries in m_ModeDatas. For each entry it:
  • Gets the ServiceCoverage component from the referenced prefab (m_Prefab).
  • If the ServiceCoverage component is missing, logs a critical error via ComponentBase.baseLog and continues.
  • Otherwise obtains the ECS Entity corresponding to the prefab via prefabSystem.GetEntity(component.prefab) and accesses the CoverageData component via entityManager.GetComponentData(entity). Purpose: ensure the CoverageData component is read (likely to register that this component will be changed — useful for change recording, undo, or serialization).

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

  • Resolves the ServiceCoverage component from the referenced prefab; logs and continues if missing.
  • Gets the corresponding Entity from the PrefabSystem.
  • Reads the current CoverageData for that entity, modifies m_Capacity, m_Range, and m_Magnitude using the ModeData values, and writes the updated CoverageData back with entityManager.SetComponentData. Effect: updates the live ECS component data for the prefab's entity so the game uses the mode-specific coverage values.

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

  • Resolves the ServiceCoverage component; logs and continues if missing.
  • Gets the corresponding Entity and reads CoverageData.
  • Restores m_Range, m_Capacity, and m_Magnitude on the CoverageData from the original ServiceCoverage component instance on the prefab, then writes it back to the entity. Effect: reverts any changes made by ApplyModeData back to the prefab's default values.

Notes on behavior and dependencies: - Requires the referenced prefab to contain a ServiceCoverage component (component on the prefab, not ECS). - Works with CoverageData (an ECS IComponentData) stored on the entity for the prefab. If the CoverageData component is not present, the code will attempt to GetComponentData which will throw/change behavior — RecordChanges is intended to ensure the component is accessed/registered first. - Error handling: uses ComponentBase.baseLog.Critical to report missing targets; it continues with remaining entries rather than throwing. - This class performs updates directly on ECS component data (EntityManager), so it should be used where it is safe to modify entities (e.g., during setup or on the main thread as required by the engine).

Usage Example

// Example: Configure a ServiceCoverageMode and apply it
var mode = new ServiceCoverageMode();
mode.m_ModeDatas = new ServiceCoverageMode.ModeData[]
{
    new ServiceCoverageMode.ModeData
    {
        m_Prefab = myServicePrefab,   // PrefabBase that has a ServiceCoverage component
        m_Range = 800f,
        m_Capacity = 2500f,
        m_Magnitude = 1.1f
    }
};

// Later, when you have access to the ECS EntityManager and PrefabSystem:
mode.RecordChanges(entityManager, prefabSystem);   // ensure component is recorded
mode.ApplyModeData(entityManager, prefabSystem);   // apply custom coverage values

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