Skip to content

Game.Prefabs.Modes.PlaceableNetGlobalMode

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

Type: class

Base: EntityQueryModePrefab

Summary:
PlaceableNetGlobalMode is a prefab mode that adjusts the XP reward value (PlaceableNetData.m_XPReward) for placeable network prefabs in bulk. It creates and schedules a Burst-compiled IJobChunk (ModeJob) that multiplies the existing XP reward by m_XPRewardMultiplier for all matching entities. The mode targets entities with PlaceableNetData and PlaceableInfoviewItem and explicitly excludes entities with FenceData. It also supports restoring the default XP reward values by reading prefab data via the PrefabSystem.


Fields

  • public float m_XPRewardMultiplier
    Multiplier applied to PlaceableNetData.m_XPReward when ApplyModeData is executed. Example: a value of 1.5 increases XP reward by 50%. This field is exposed on the mode for configuration (e.g., set in editor or by code).

  • private struct ModeJob (nested)
    Burst-compiled IJobChunk implementation used to process chunks of entities in parallel. ModeJob holds:

  • public float m_XPRewardMultiplier — copied from the mode instance.
  • public ComponentTypeHandle<PlaceableNetData> m_PlaceableNetType — handle used to get writable PlaceableNetData arrays.
  • Execute method: iterates chunk entities and updates each PlaceableNetData.m_XPReward by multiplying with m_XPRewardMultiplier.

Properties

  • This class declares no public properties.

Constructors

  • public PlaceableNetGlobalMode()
    No explicit constructor is defined in source; the default parameterless constructor is used. Configuration is typically done by setting m_XPRewardMultiplier after instantiation or via the editor.

Methods

  • public override EntityQueryDesc GetEntityQueryDesc()
    Returns an EntityQueryDesc that matches entities containing PlaceableNetData (read-only) and PlaceableInfoviewItem (read-only) and excludes entities with FenceData. This query is used to select which prefab entities the mode will affect.

  • protected override void RecordChanges(EntityManager entityManager, Entity entity)
    Called to record current component data for change/undo purposes. This implementation reads PlaceableNetData for the provided entity (entityManager.GetComponentData(entity)) to ensure the original value is recorded.

  • public override JobHandle ApplyModeData(EntityManager entityManager, EntityQuery requestedQuery, JobHandle deps)
    Schedules the Burst-compiled ModeJob in parallel over requestedQuery. The job is initialized with:

  • m_XPRewardMultiplier from this mode instance,
  • a writable ComponentTypeHandle obtained from the provided EntityManager. Returns the resulting JobHandle.

  • public override void RestoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
    Restores the default PlaceableNetData.m_XPReward for each entity in the provided entities array by:

  • Trying to resolve the prefab via prefabSystem.TryGetPrefab(entity, out prefabBase).
  • Attempting to get the PlaceableNet component from the prefab (prefabBase.TryGetExactly(out var component)).
  • If successful, it reads component.m_XPReward from the prefab and sets that value back onto the entity's PlaceableNetData via entityManager.SetComponentData. If the prefab or component cannot be resolved, a warning is logged and the entity is skipped.

  • ModeJob.Execute(...) (IJobChunk)
    Per-chunk worker that multiplies each PlaceableNetData.m_XPReward by the configured multiplier. Implemented with BurstCompile attribute for high performance.

Usage Example

// Example: configure and schedule the mode from code (simplified)
var mode = new PlaceableNetGlobalMode();
mode.m_XPRewardMultiplier = 1.5f; // increase XP rewards by 50%

// In real usage the engine/framework calls ApplyModeData with a proper EntityManager and EntityQuery.
// Example signature shown for clarity:
JobHandle handle = mode.ApplyModeData(entityManager, requestedQuery, JobHandle.CombineDependencies(existingDeps));

Additional notes and tips: - The job is Burst-compiled and uses ComponentTypeHandle with isReadOnly:false, so it writes directly to PlaceableNetData. Ensure no other systems are concurrently writing the same component unless properly synchronized via JobHandles. - The entity query excludes fences (FenceData) to avoid unintentionally modifying fence prefabs. - RestoreDefaultData relies on PrefabSystem and PrefabBase.TryGetExactly to obtain the original prefab values—if modded or missing prefabs exist, restoration may fail and will be logged. - Because m_XPReward is an integer on PlaceableNetData, the multiplication casts/rounds via (int)((float)existing * multiplier) as implemented in the job. Be aware of truncation effects when using non-integer multipliers.