Skip to content

Game.Prefabs.Modes.MailAccumulationGlobalMode

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

Type: class

Base: EntityQueryModePrefab

Summary:
A mode prefab that applies global multipliers to mail accumulation rates for entities that have MailAccumulationData. It schedules a Burst-compiled IJobChunk (ModeJob) which multiplies the m_AccumulationRate float2 (x = sending, y = receiving) by the configured m_SendingRateMultiplier and m_ReceivingRateMultiplier. Provides methods to create the EntityQuery, apply the mode (scheduling the job), record changes, and restore default values from prefab data.


Fields

  • public float m_SendingRateMultiplier
    Controls the multiplier applied to the sending component (x) of MailAccumulationData.m_AccumulationRate when the mode is applied. Typical values: 1.0 (no change), <1 to reduce, >1 to increase.

  • public float m_ReceivingRateMultiplier
    Controls the multiplier applied to the receiving component (y) of MailAccumulationData.m_AccumulationRate when the mode is applied. Typical values: 1.0 (no change), <1 to reduce, >1 to increase.

  • (nested) private struct ModeJob : IJobChunk
    Burst-compiled job used to process chunks of entities containing MailAccumulationData. Fields inside ModeJob:

  • public float m_SendingRateMultiplier — copied from the mode instance.
  • public float m_ReceivingRateMultiplier — copied from the mode instance.
  • public ComponentTypeHandle<MailAccumulationData> m_MailAccumulateType — handle used to read/write MailAccumulationData in the job.

Properties

  • None declared on this class.

Constructors

  • public MailAccumulationGlobalMode()
    No explicit constructor in source; the class uses the default constructor provided by Unity/Mono. Initialization of multipliers is expected to be done via inspector or by setting the public fields from code.

Methods

  • public override EntityQueryDesc GetEntityQueryDesc()
    Returns an EntityQueryDesc that matches entities with MailAccumulationData (read-only as declared). This query is used to select the entities affected by the mode.

  • protected override void RecordChanges(EntityManager entityManager, Entity entity)
    Called to record/backup current component data (framework-specific). It reads MailAccumulationData for the given entity via entityManager.GetComponentData(entity). This is used so the system can later restore original values if needed.

  • public override JobHandle ApplyModeData(EntityManager entityManager, EntityQuery requestedQuery, JobHandle deps)
    Schedules the Burst-compiled ModeJob in parallel over the requestedQuery. The job multiplies each entity's MailAccumulationData.m_AccumulationRate.x by m_SendingRateMultiplier and .y by m_ReceivingRateMultiplier. Returns the scheduled JobHandle. It obtains a non-read-only ComponentTypeHandle from the provided EntityManager for writing.

  • public override void RestoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
    Iterates over the provided entities and restores each entity's MailAccumulationData.m_AccumulationRate to the default values from the prefab. It uses PrefabSystem.TryGetPrefab and PrefabBase.TryGetExactly to get the original MailAccumulation component values (m_SendingRate, m_ReceivingRate). If prefab data cannot be found, a warning is logged via ComponentBase.baseLog.Warn. After retrieving the prefab values, it sets the entity's component data accordingly.

  • (nested) ModeJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    The job implementation. For each chunk it gets a NativeArray and iterates through entities in the chunk, updating each element's m_AccumulationRate to: new float2(old.x * m_SendingRateMultiplier, old.y * m_ReceivingRateMultiplier)

  • (nested) void IJobChunk.Execute(...)
    Explicit interface forwarder that calls the internal Execute method.

Usage Example

// Example: configure and apply the mode from game code
var mode = /* obtain reference to the MailAccumulationGlobalMode prefab/component */;
mode.m_SendingRateMultiplier = 0.5f;   // reduce sending rate to 50%
mode.m_ReceivingRateMultiplier = 1.25f; // increase receiving rate to 125%

EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var queryDesc = mode.GetEntityQueryDesc();
EntityQuery query = entityManager.CreateEntityQuery(queryDesc);

// Schedule the job on the current dependency chain:
JobHandle handle = mode.ApplyModeData(entityManager, query, default);

// If needed, you can wait for completion:
// handle.Complete();

Additional notes: - The job is Burst-compiled and scheduled via ScheduleParallel, so it is safe and efficient for large numbers of entities. - RestoreDefaultData depends on prefab metadata (MailAccumulation) being available; missing prefab entries are logged and skipped. - The EntityQuery returned by GetEntityQueryDesc selects entities that have MailAccumulationData; ensure entities have that component to be affected.