Game.Net.AggregateElement
Assembly: Assembly-CSharp.dll
Namespace: Game.Net
Type: struct
Base: IBufferElementData, IEquatable
Summary:
AggregateElement is a small value-type buffer element used by the game's ECS to represent an "edge" entity in aggregation/networking contexts. It is serializable via the Colossal.Serialization framework and implements equality and hashing based on the contained Entity reference. Typically stored in a DynamicBuffer
Fields
public Unity.Entities.Entity m_Edge
A Unity.Entities.Entity that represents the edge associated with this aggregate element. This is the sole data carried by the element; equality and hash code are derived from this field. When not explicitly set, the field contains the default Entity value (usually Entity.Null).
Properties
- This struct does not declare any C# properties. It exposes the entity only via the public field m_Edge.
Constructors
public AggregateElement(Unity.Entities.Entity edge)
Constructs a new AggregateElement and sets m_Edge to the provided entity. The struct also has the implicit default constructor (which leaves m_Edge at its default value).
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the contained Entity using the provided writer's Write method. Used by the Colossal.Serialization system to persist or network the buffer contents. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes the contained Entity by calling reader.Read(out m_Edge). Used by the Colossal.Serialization system to restore the element from serialized data. -
public bool Equals(AggregateElement other)
Implements IEquatable. Compares this element to another by delegating to m_Edge.Equals(other.m_Edge). -
public override int GetHashCode()
Returns the hash code of the contained Entity (m_Edge.GetHashCode()), suitable for use in hash-based collections.
Usage Example
// Example: creating an entity that contains a DynamicBuffer<AggregateElement>
// and adding an edge entity reference to it.
using Unity.Entities;
using Game.Net;
// assume world/entityManager and an edge entity are available
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
// Create an entity that will hold the buffer
Entity aggregator = em.CreateEntity(typeof(AggregateElement)); // note: in real usage you would create a buffer component type, e.g. typeof(DynamicBuffer<AggregateElement>)
// Get the buffer and add an AggregateElement
DynamicBuffer<AggregateElement> buffer = em.GetBuffer<AggregateElement>(aggregator);
Entity edgeEntity = /* obtain or create the edge Entity */;
buffer.Add(new AggregateElement(edgeEntity));
// The element will serialize/deserialize via Colossal.Serialization when the game's save/network code runs.