Skip to content

Game.Prefabs.Modes.PlaceableNetPieceGlobalMode

Assembly:
Namespace: Game.Prefabs.Modes

Type: class

Base: EntityQueryModePrefab

Summary:
PlaceableNetPieceGlobalMode is a mode prefab that applies global multipliers to PlaceableNetPieceData for matching entities. It uses a Burst-compiled IJobChunk (ModeJob) to multiply construction cost, elevation cost and upkeep costfor all PlaceableNetPiece components in the provided EntityQuery. The mode also supports restoring original prefab values via PrefabSystem when needed.


Fields

  • private struct ModeJob
    Nested Burst-compiled IJobChunk that performs the per-chunk cost modifications. It contains job fields and the chunk Execute implementation.

  • public float m_ConstructionCostMultiplier
    Multiplier applied to PlaceableNetPieceData.m_ConstructionCost inside the job.

  • public float m_ElevationCostMultiplier
    Multiplier applied to PlaceableNetPieceData.m_ElevationCost inside the job.

  • public float m_UpkeepCostMultiplier
    Multiplier applied to PlaceableNetPieceData.m_UpkeepCost inside the job.

  • public ComponentTypeHandle<PlaceableNetPieceData> m_PlaceableNetPieceType
    ComponentTypeHandle used to access PlaceableNetPieceData in the chunk.

Description: ModeJob iterates over each PlaceableNetPieceData in a chunk and multiplies the numeric fields: - m_ConstructionCost is converted to float, multiplied, then cast back to uint. - m_ElevationCost is converted to float, multiplied, then cast back to uint. - m_UpkeepCost is multiplied as a float.

  • public float m_ConstructionCostMultiplier
    Public field on the prefab instance used to configure the construction cost multiplier applied by the ModeJob.

  • public float m_ElevationCostMultiplier
    Public field on the prefab instance used to configure the elevation cost multiplier applied by the ModeJob.

  • public float m_UpkeepCostMultiplier
    Public field on the prefab instance used to configure the upkeep multiplier applied by the ModeJob.

Properties

  • None (no public properties declared on PlaceableNetPieceGlobalMode).
    The job uses a ComponentTypeHandle obtained at schedule time.

Constructors

  • public PlaceableNetPieceGlobalMode()
    No explicit constructor is declared in source; the default parameterless constructor is used. Initialization of multipliers typically happens via inspector/prefab data.

Methods

  • public override EntityQueryDesc GetEntityQueryDesc()
    Returns an EntityQueryDesc that selects entities containing a ReadOnly PlaceableNetPieceData component. This query is used when scheduling the ModeJob.

Behavior: builds EntityQueryDesc with All = ComponentType.ReadOnly().

  • protected override void RecordChanges(EntityManager entityManager, Entity entity)
    Called to record that this entity's PlaceableNetPieceData will be changed (used by the mode/prefab system to track modifications). Implementation calls entityManager.GetComponentData(entity) (likely to mark the component or to fetch a value for recording).

  • public override JobHandle ApplyModeData(EntityManager entityManager, EntityQuery requestedQuery, JobHandle deps)
    Creates and schedules the Burst-compiled ModeJob in parallel over the requestedQuery. It populates ModeJob fields with the current multipliers and obtains a non-readonly ComponentTypeHandle from the EntityManager. Returns the JobHandle for the scheduled job.

  • public override void RestoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
    Restores original PlaceableNetPieceData values for a set of entities using prefab data. For each entity:

  • Tries to get PrefabBase for the entity via prefabSystem.TryGetPrefab.
  • Attempts to retrieve a PlaceableNetPiece component from the prefab base via TryGetExactly.
  • If successful, reads the component's m_ConstructionCost, m_ElevationCost, m_UpkeepCost and writes them back into the entity's PlaceableNetPieceData via entityManager.SetComponentData.
  • If prefab data is not found, logs a warning via ComponentBase.baseLog.Warn.

  • ModeJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    The actual per-chunk implementation that iterates chunk.GetNativeArray(ref m_PlaceableNetPieceType) and applies the multipliers to each PlaceableNetPieceData element.

  • void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Explicit interface implementation forwarding to the concrete Execute method.

Usage Example

// Configure a mode instance (usually set in prefab/inspector)
var mode = new PlaceableNetPieceGlobalMode();
mode.m_ConstructionCostMultiplier = 0.5f; // halve construction cost
mode.m_ElevationCostMultiplier = 1.0f;   // keep elevation cost
mode.m_UpkeepCostMultiplier = 0.75f;     // reduce upkeep to 75%

// The game's mode/prefab system will call GetEntityQueryDesc() / ApplyModeData()
// to schedule the job when activating this mode. RestoreDefaultData(...) is called
// by the system to revert entities back to their prefab values when needed.