Skip to content

Game.Prefabs.Modes.ProcessingCompanyGlobalMode

Assembly: Assembly-CSharp (game/project assembly; exact assembly may vary)
Namespace: Game.Prefabs.Modes

Type: class

Base: EntityQueryModePrefab

Summary:
ProcessingCompanyGlobalMode is a mode prefab used to globally modify the input requirements and output production of processing (industrial) companies. It finds entities that have an IndustrialProcessData component and scales their input and output amounts using m_InputMultiplier and m_OutputMultiplier. The actual per-entity modifications are performed in a Burst-compiled IJobChunk (ModeJob) scheduled in parallel for the requested EntityQuery. The original component data for entities is stored in m_OriginalData so it can be restored later.


Fields

  • public float m_InputMultiplier
    This multiplier is applied to each processing component's input amounts (m_Input1.m_Amount and m_Input2.m_Amount). Values are multiplied and then cast to int, so fractional results are truncated. Set this in the inspector to increase/decrease input requirements for all matching processing companies.

  • public float m_OutputMultiplier
    This multiplier is applied to each processing component's output amount (m_Output.m_Amount). Like inputs, results are cast to int and will be truncated. Set this to scale production outputs globally.

  • private System.Collections.Generic.Dictionary<Entity, IndustrialProcessData> m_OriginalData
    A dictionary that maps entities to their original IndustrialProcessData captured by StoreDefaultData. Used by RestoreDefaultData to restore components to their original values when the mode is disabled or reverted. This dictionary is populated on the main thread and accessed only on the main thread (no jobs use it directly).

Properties

This class does not declare any properties.

Constructors

  • public ProcessingCompanyGlobalMode()
    Default constructor (implicit). Initialization of fields occurs via serialized values (m_InputMultiplier, m_OutputMultiplier) and at runtime through StoreDefaultData. No special construction logic is implemented in the class.

Methods

  • public override EntityQueryDesc GetEntityQueryDesc()
    Returns an EntityQueryDesc that selects all entities with the IndustrialProcessData component (read-only in the query description). This query is used to find all processing company entities that should be modified by this mode.

  • protected override void RecordChanges(EntityManager entityManager, Entity entity)
    Called to record changes for a single entity. In this implementation it simply reads the IndustrialProcessData component via entityManager.GetComponentData(entity). (Note: this method reads the component but does not store it here — the purpose may be to mark the component as observed/changed in the surrounding system.)

  • public override void StoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
    Iterates the supplied entities array and stores each entity's current IndustrialProcessData in m_OriginalData. This allows the mode to later restore original values. m_OriginalData is created with an initial capacity based on entities.Length.

  • public override JobHandle ApplyModeData(EntityManager entityManager, EntityQuery requestedQuery, JobHandle deps)
    Schedules the Burst-compiled ModeJob (IJobChunk) in parallel using JobChunkExtensions.ScheduleParallel. The ModeJob is configured with:

  • m_InputMultiplier and m_OutputMultiplier from this prefab instance
  • a ComponentTypeHandle (isReadOnly: false) fetched from the EntityManager

The job multiplies each entity's inputs and outputs inside the chunk. Returns the scheduled JobHandle so the caller can chain dependencies.

  • public override void RestoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
    Restores stored IndustrialProcessData for each entity from m_OriginalData by calling entityManager.SetComponentData(entity, value). If an entity is not found in m_OriginalData, the method adds the entity's current component value into the dictionary (this preserves a record for future restores).

Nested private type (job)

  • private struct ModeJob : IJobChunk (Burst-compiled)
  • Fields:
    • public float m_InputMultiplier — multiplier applied to each input amount.
    • public float m_OutputMultiplier — multiplier applied to the output amount.
    • public ComponentTypeHandle<IndustrialProcessData> m_ProcessingType — ComponentTypeHandle used to read/write IndustrialProcessData in chunks.
  • Execution:
    • Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
      For each IndustrialProcessData in the chunk, multiplies m_Input1.m_Amount and m_Input2.m_Amount by m_InputMultiplier and m_Output.m_Amount by m_OutputMultiplier, casting results to int and writing back the component.
    • Implements IJobChunk.Execute explicitly as required by the job interface.
  • Notes:
    • Burst compiled for performance.
    • The job writes to IndustrialProcessData (ComponentTypeHandle is not read-only).
    • Multiplication results are converted to int, which truncates fractional values — this can cause rounding down.

Usage Example

// This example demonstrates how the prefab's multipliers affect stored data.
// Typically this prefab is added to a mode system and applied by the game's prefab system.

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Assume 'this' is an instance of ProcessingCompanyGlobalMode set up via inspector
    // m_InputMultiplier = 0.5f;  // reduce input requirements by half
    // m_OutputMultiplier = 1.2f; // increase outputs by 20%
}

// When the mode is applied by the prefabs/mode system, ApplyModeData is called.
// It will schedule a parallel Burst job that multiplies input/output amounts for all
// entities that match the query (entities with IndustrialProcessData).

Notes and caveats - The job performs integer casts after floating-point multiplication — small multipliers or fractional changes may be lost due to truncation. Consider using rounding if preserving values is important. - m_OriginalData is stored on the main thread; the class assumes StoreDefaultData runs before any ApplyModeData calls and RestoreDefaultData runs on the main thread as well. - The ModeJob uses a non-read-only ComponentTypeHandle to modify components in-place; ensure no conflicting jobs write the same components concurrently. - Burst and Jobs require appropriate safety/permission in the mod environment — ensure the target runtime supports Burst and Unity.Entities job scheduling used here.