Skip to content

Game.Prefabs.Modes.ZoneServiceConsumptionGlobalMode

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

Type: class

Base: EntityQueryModePrefab

Summary:
ZoneServiceConsumptionGlobalMode is a prefab-mode class that globally modifies the upkeep and utility-related consumption values for zone buildings. It applies configurable multipliers (upkeep, electricity, water, garbage accumulation, telecom need) to the ConsumptionData component of matching entities using a Burst-compiled, parallel IJobChunk (ModeJob). The class also stores original ConsumptionData for each affected entity so the modifications can be reverted later.


Fields

  • public float m_UpkeepMultiplier
    Multiplier applied to ConsumptionData.m_Upkeep. The code multiplies the integer upkeep by this float and casts back to int (truncation/flooring risk).

  • public float m_ElectricityConsumptionMultiplier
    Multiplier applied to ConsumptionData.m_ElectricityConsumption (float).

  • public float m_WaterConsumptionMultiplier
    Multiplier applied to ConsumptionData.m_WaterConsumption (float).

  • public float m_GarbageAccumlationMultiplier
    Multiplier applied to ConsumptionData.m_GarbageAccumulation (float). Note the field name contains a misspelling ("Accumlation") that matches the source code.

  • public float m_TelecomNeedMultiplier
    Multiplier applied to ConsumptionData.m_TelecomNeed (float).

  • private Dictionary<Entity, ConsumptionData> m_OriginalConsumptionData
    Dictionary used to store the original ConsumptionData for each entity when StoreDefaultData is called, allowing RestoreDefaultData to put values back.

  • (nested) private struct ModeJob (Burst-compiled)
    Contains the per-job copies of multipliers and a ComponentTypeHandle. ModeJob implements IJobChunk and applies multipliers to every ConsumptionData in a chunk in Execute(...).

ModeJob fields: - public float m_UpkeepMultiplier - public float m_ElectricityConsumptionMultiplier - public float m_WaterConsumptionMultiplier - public float m_GarbageAccumlationMultiplier - public float m_TelecomNeedMultiplier - public ComponentTypeHandle<ConsumptionData> m_ConsumptionType

ModeJob behavior: - Iterates the chunk's ConsumptionData array. - Applies m_UpkeepMultiplier to value.m_Upkeep and casts to int. - Multiplies the other float consumption fields by their respective multipliers. - Writes the modified ConsumptionData back to the chunk's array. - Marked with [BurstCompile] for performance.

Properties

  • None (no public properties declared on this class).

Constructors

  • public ZoneServiceConsumptionGlobalMode()
    No explicit constructor is declared in the source; the default parameterless constructor is used. All multiplier fields are exposed and typically initialized via the Unity inspector on the prefab.

Methods

  • public override EntityQueryDesc GetEntityQueryDesc()
    Returns an EntityQueryDesc that matches entities containing both ConsumptionData and SpawnableBuildingData components (both read-only in the query). This query defines which entities the job will operate on.

  • protected override void RecordChanges(EntityManager entityManager, Entity entity)
    Intended to record changes for the provided entity. The implementation calls entityManager.GetComponentData<ConsumptionData>(entity) (reads the component), presumably to mark it or to trigger change-tracking in the system that calls this method.

  • public override void StoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
    Iterates the supplied entities and stores a copy of each entity's ConsumptionData in m_OriginalConsumptionData (keyed by Entity). Called before applying mode changes to preserve original values so they can be restored later.

  • public override JobHandle ApplyModeData(EntityManager entityManager, EntityQuery requestedQuery, JobHandle deps)
    Schedules the Burst-compiled ModeJob in parallel (via JobChunkExtensions.ScheduleParallel) using the provided requestedQuery. The method constructs a ModeJob instance populated with this class's multiplier fields and a ComponentTypeHandle (non-readonly). Returns the JobHandle for dependency chaining.

  • public override void RestoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
    Restores ConsumptionData for each entity from m_OriginalConsumptionData if present. If an entity is not present in the dictionary, it reads the current component from the entity and adds it to the dictionary (ensuring future restores have an entry).

  • (nested) private struct ModeJob : IJobChunk (Burst compiled)
    See Fields section for details. Implements Execute(...) to modify ConsumptionData per-chunk.

Notes / Implementation details and caveats: - The job is Burst-compiled and scheduled parallel, so operations are designed for multi-threaded execution. The use of ComponentTypeHandle is correct for chunk-based writing. - Upkeep is an integer in ConsumptionData; the multiplier is floating-point, and the code casts the result to int. That may truncate fractional results — intentional or not. - The class stores original data in a Dictionary. For large numbers of entities this may have memory/performance implications; ensure StoreDefaultData is called at appropriate times. - Field spelling: m_GarbageAccumlationMultiplier contains a typo ("Accumlation"). Keep consistent when referencing the field. - GetEntityQueryDesc marks the ConsumptionData as read-only in the ComponentType array, but ApplyModeData obtains a non-read-only ComponentTypeHandle — the read-only marker in the EntityQueryDesc is used only for creating the query; the job actually writes to the component.

Usage Example

// Example: Configure multipliers in code (e.g. on prefab initialization)
// The class fields are serialized and typically set in the prefab inspector,
// but you can also set them from code before the mode gets applied.

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Example adjustments:
    // Increase upkeep by 20%, reduce electricity use to 90%, slightly increase garbage accumulation.
    m_UpkeepMultiplier = 1.2f;
    m_ElectricityConsumptionMultiplier = 0.9f;
    m_WaterConsumptionMultiplier = 1.0f;
    m_GarbageAccumlationMultiplier = 1.1f;
    m_TelecomNeedMultiplier = 1.0f;
}