Game.Net.LaneObjectCommandBuffer
Assembly: Assembly-CSharp
Namespace: Game.Net
Type: struct
Base: System.ValueType
Summary:
A lightweight command buffer used to enqueue add, remove and update actions for lane objects and tree objects. Internally it wraps a NativeParallelQueue writer for lane-related actions and a NativeQueue
Fields
-
private System.Diagnostics.Stopwatch m_Stopwatch
This file does not declare this field. (Included in the template example but not present in this type.) -
private Unity.Jobs.JobHandle <producerHandle>k__BackingField
This file does not declare this field. (Included in the template example but not present in this type.) -
private NativeParallelQueue<LaneObjectAction>.Writer m_LaneActionQueue
Writer for a NativeParallelQueue of LaneObjectAction. Used to enqueue actions that target specific lanes (add/remove/update lane-attached objects). This writer is suitable for single-writer contexts; NativeParallelQueue provides thread-safe enqueuing when using its Writer. -
private NativeQueue<TreeObjectAction>.ParallelWriter m_TreeActionQueue
ParallelWriter for a NativeQueue of TreeObjectAction. Used to enqueue actions that target tree (scene) objects. The ParallelWriter variant allows safe parallel enqueues from worker jobs.
Properties
- This type has no public properties.
Constructors
public LaneObjectCommandBuffer(NativeParallelQueue<LaneObjectAction>.Writer laneActionQueue, NativeQueue<TreeObjectAction>.ParallelWriter treeActionQueue)
Creates a new command buffer that will enqueue lane and tree object actions to the provided queue writers. Both writers must be valid and initialized before constructing this struct. The constructor simply stores the provided writers for later enqueue operations.
Methods
-
public void Remove(Entity lane, Entity entity)
Enqueues a LaneObjectAction representing removal of the specified entity from the specified lane. Use when removing an object attached to a lane. -
public void Remove(Entity entity)
Enqueues a TreeObjectAction representing removal of the specified scene/tree entity. Use for deleting standalone tree objects (or similar non-lane objects). -
public void Add(Entity lane, Entity entity, float2 curvePosition)
Enqueues a LaneObjectAction that represents adding the specified entity to the given lane at the provided curve position (float2). Use this to spawn or attach objects to lanes. -
public void Add(Entity entity, Bounds3 bounds)
Enqueues a TreeObjectAction that represents adding the specified entity with the given world bounds. Use to create/place tree-like objects or other scene entities that are not lane-attached. -
public void Update(Entity lane, Entity entity, float2 curvePosition)
Enqueues a LaneObjectAction that represents updating an existing lane-attached entity's position along the lane curve. Note: the implementation uses the LaneObjectAction constructor overload with (lane, entity, entity, curvePosition) — presumably to encode both target lane and target entity plus any required metadata. -
public void Update(Entity entity, Bounds3 bounds)
Enqueues a TreeObjectAction that represents updating an existing scene/tree entity's bounds. The implementation passes (entity, entity, bounds) to the TreeObjectAction constructor — presumably encoding the target and new bounds.
Notes on behavior: - The struct is a simple wrapper; it performs no validation of the Entity values or values passed. Validation and execution responsibility falls to the system that consumes the queued actions. - Intended for enqueuing from both main thread and job contexts (use appropriate writer types). Ensure the underlying queues are allocated with suitable Lifetime and concurrency rules. - The exact layout and semantics of LaneObjectAction and TreeObjectAction are not defined here; they encapsulate the data needed by the consumer to apply the requested changes.
Usage Example
// Example usage in a system or manager:
// Prepare queues somewhere in owning system:
var laneActionQueue = new NativeParallelQueue<LaneObjectAction>(Allocator.Persistent);
var treeQueue = new NativeQueue<TreeObjectAction>(Allocator.Persistent);
// Obtain writers (example on main thread):
var laneWriter = laneActionQueue.AsWriter();
var treeParallelWriter = treeQueue.AsParallelWriter(); // for parallel use in jobs
// Construct the command buffer:
var cmdBuffer = new Game.Net.LaneObjectCommandBuffer(laneWriter, treeParallelWriter);
// Enqueue operations:
cmdBuffer.Add(laneEntity, objectEntity, new float2(0.5f, 0.0f)); // add to lane at curve position
cmdBuffer.Update(laneEntity, objectEntity, new float2(0.6f, 0.0f)); // update lane-attached object
cmdBuffer.Remove(laneEntity, objectEntity); // remove lane-attached object
cmdBuffer.Add(treeEntity, new Bounds3(...)); // add a tree/scene object
cmdBuffer.Update(treeEntity, new Bounds3(...)); // update tree/scene object bounds
cmdBuffer.Remove(treeEntity); // remove tree/scene object
// Later, a consumer system dequeues LaneObjectAction and TreeObjectAction and applies the changes.
Additional tips: - Ensure the NativeParallelQueue and NativeQueue are disposed when no longer needed. - When enqueuing from jobs, use the correct writer variants and respect Unity.Collections safety rules (e.g., pass in proper job handles if scheduling).