Game.ElectricityConnectionGlobalMode
Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes
Type: class
Base: EntityQueryModePrefab
Summary:
ElectricityConnectionGlobalMode is a mode prefab used to apply a global multiplier to the capacity of electricity connections in the Entities world. It schedules a Burst-compiled IJobChunk (ModeJob) that iterates matching entities (those with ElectricityConnectionData) and multiplies their m_Capacity by m_CapacityMultiplier. It also provides logic to restore default capacity values from prefab data via RestoreDefaultData.
Fields
-
public float m_CapacityMultiplier
This multiplier is applied to ElectricityConnectionData.m_Capacity for every matched entity when ApplyModeData is called. Typical values >1 increase capacity, values <1 reduce it. -
(inner)
private struct ModeJob : IJobChunk
Burst-compiled job struct used by ApplyModeData. Contains: public float m_CapacityMultiplier
— the multiplier passed from the mode instance.public ComponentTypeHandle<ElectricityConnectionData> m_ElectricityConnectionType
— non-readonly handle to read/write ElectricityConnectionData.- Execute(in ArchetypeChunk chunk, ...) — iterates the chunk's ElectricityConnectionData array and sets each element's m_Capacity = (int)(m_Capacity * m_CapacityMultiplier).
Properties
- This type exposes no public properties.
Constructors
public ElectricityConnectionGlobalMode()
Default constructor (implicit). No special initialization is required by the prefab itself; m_CapacityMultiplier should be set on the prefab instance (e.g., in the editor or via code) before ApplyModeData is invoked.
Methods
-
public override EntityQueryDesc GetEntityQueryDesc()
Returns an EntityQueryDesc that selects entities containing ElectricityConnectionData (read-only in the query description). This query is used to find targets for the ModeJob. -
protected override void RecordChanges(EntityManager entityManager, Entity entity)
Records changes for the given prefab entity by calling entityManager.GetComponentData(entity). This forces a read/access which can be used by systems tracking changes. -
public override JobHandle ApplyModeData(EntityManager entityManager, EntityQuery requestedQuery, JobHandle deps)
Schedules the Burst-compiled ModeJob using JobChunkExtensions.ScheduleParallel. It obtains a writable ComponentTypeHandlefrom the EntityManager and passes the instance's m_CapacityMultiplier into the job. Returns the resulting JobHandle for dependency chaining. -
public override void RestoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
Restores default capacity values for the supplied entities from their prefab definitions. For each entity: - Attempts to get the PrefabBase via prefabSystem.TryGetPrefab
(entity, out prefabBase). - Attempts to fetch the ElectricityConnection component from the prefab (prefabBase.TryGetExactly
(out var component)). - If prefab/component not found, logs a warning and continues.
- Otherwise reads current ElectricityConnectionData from the entity, sets componentData.m_Capacity = component.m_Capacity (prefab default), and writes it back with entityManager.SetComponentData.
Notes: - The ModeJob is Burst-compiled for performance. - ModeJob performs integer cast after multiplication; small floating rounding differences may occur. - The ComponentTypeHandle is requested with isReadOnly: false to allow writes. - The job is scheduled in parallel across chunks.
Usage Example
// Example usage inside a system or initialization code:
var mode = new ElectricityConnectionGlobalMode();
mode.m_CapacityMultiplier = 1.5f; // increase capacity by 50%
// Acquire required ECS objects:
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
EntityQuery query = entityManager.CreateEntityQuery(mode.GetEntityQueryDesc());
JobHandle deps = default;
// Schedule the mode job and get a handle to chain further work:
deps = mode.ApplyModeData(entityManager, query, deps);
// Later, ensure completion if needed:
// deps.Complete();
Additional implementation notes: - Requires Unity.Entities, Unity.Jobs, Unity.Collections, Unity.Burst namespaces (already used in the original code). - Works with ECS IJobChunk API and expects ElectricityConnectionData and ElectricityConnection prefab component types to exist in the project.