Game.Effects.SourceUpdateData
Assembly:
Namespace: Game.Effects
Type: struct
Base: System.ValueType
Summary:
A small value-type helper that wraps a NativeQueue
Fields
private NativeQueue<SourceUpdateInfo>.ParallelWriter m_SourceUpdateQueue
Holds the ParallelWriter into which update entries are enqueued. This enables safe concurrent enqueue operations from multiple job threads. The queue instance itself must be created and disposed by the owner (usually within a system or job setup/teardown), and this struct only stores the ParallelWriter.
Properties
- None
Constructors
public SourceUpdateData(NativeQueue<SourceUpdateInfo>.ParallelWriter sourceUpdateQueue)
Initializes the struct with the provided ParallelWriter. Use NativeQueue.AsParallelWriter() when creating the value to pass here (e.g., queue.AsParallelWriter()).
Methods
-
public void Add(Entity entity, Transform transform)
Enqueues a SourceUpdateInfo with Type = SourceUpdateType.Add, creating a SourceInfo from the given entity (instance id -1). Includes the Transform when available (used for positioning/initialization of the source instance). -
public void Add(SourceInfo sourceInfo)
Enqueues a SourceUpdateInfo with Type = SourceUpdateType.Add for an already-constructed SourceInfo (no Transform provided). -
public void AddTemp(Entity prefab, Transform transform)
Enqueues a SourceUpdateInfo with Type = SourceUpdateType.Temp for temporary sources created from a prefab Entity and associated Transform. -
public void AddSnap()
Enqueues a SourceUpdateInfo with Type = SourceUpdateType.Snap. This is used to request a "snapshot" or similar global update event; no SourceInfo is attached. -
public void Remove(Entity entity)
Enqueues a SourceUpdateInfo with Type = SourceUpdateType.Remove for the provided entity (SourceInfo constructed with instance id -1). -
public void Remove(SourceInfo sourceInfo)
Enqueues a SourceUpdateInfo with Type = SourceUpdateType.Remove for the given SourceInfo. -
public void WrongPrefab(SourceInfo sourceInfo)
Enqueues a SourceUpdateInfo with Type = SourceUpdateType.WrongPrefab for the given SourceInfo. Use this to notify systems that the prefab instance does not match the expected source prefab.
Usage Example
// Example usage inside a System or job setup
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
using Game.Effects;
// Create a queue (owner must dispose when done)
var queue = new NativeQueue<SourceUpdateInfo>(Allocator.TempJob);
// Get a parallel writer and wrap in SourceUpdateData
var writer = queue.AsParallelWriter();
var sourceUpdate = new SourceUpdateData(writer);
// Enqueue updates (can be called from jobs or multithreaded contexts)
Entity someEntity = /* obtain entity */;
Transform someTransform = /* obtain transform */;
sourceUpdate.Add(someEntity, someTransform);
// Enqueue a snapshot event
sourceUpdate.AddSnap();
// When finished, the system that owns 'queue' should dequeue and process SourceUpdateInfo entries,
// then dispose the queue when appropriate.