Game.Events.TargetElement
Assembly: Assembly-CSharp
Namespace: Game.Events
Type: struct
Base: System.ValueType
(implements Unity.Entities.IBufferElementData, System.IEquatable
Summary:
TargetElement is a lightweight buffer element used to store a Unity.Entities.Entity inside a DynamicBuffer. The struct is marked with [InternalBufferCapacity(0)], indicating no internal pre-allocated capacity for the buffer on the entity (saves memory if variable-sized). It provides equality and hash-code implementations based on the contained Entity and implements Colossal.Serialization.Entities.ISerializable to support writing/reading the Entity value for save/load or network serialization.
Fields
public Unity.Entities.Entity m_Entity
Holds the Entity reference stored in this buffer element. Used as the identity for equality and hashing, and is the value serialized/deserialized by the ISerializable implementation.
Properties
- None. (This type exposes its data as a public field rather than properties.)
Constructors
public TargetElement(Unity.Entities.Entity entity)
Initializes a new TargetElement wrapping the provided Entity.
Methods
-
public bool Equals(TargetElement other)
Compares this TargetElement to another by delegating to Entity.Equals on the contained m_Entity. -
public override int GetHashCode()
Returns the hash code of the contained m_Entity. -
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the contained Entity to the provided writer. Used by the Colossal serialization system. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads an Entity value from the provided reader into m_Entity. Used by the Colossal serialization system.
Usage Example
// Add an entity reference to a DynamicBuffer<TargetElement> on a container entity
public partial class ExampleSystem : SystemBase
{
protected override void OnUpdate()
{
var em = EntityManager;
Entities.ForEach((Entity containerEntity, ref SomeTag tag) =>
{
// Ensure the container has the buffer
if (!em.HasComponent<TargetElement>(containerEntity))
em.AddBuffer<TargetElement>(containerEntity);
var buffer = em.GetBuffer<TargetElement>(containerEntity);
// Example: add a target entity (otherEntity is an Entity you obtained elsewhere)
Entity otherEntity = /* obtain entity */;
buffer.Add(new TargetElement(otherEntity));
}).WithoutBurst().Run();
}
}
// Serialization is handled automatically by the Colossal serialization system
// because TargetElement implements ISerializable; during save/load the
// Serialize/Deserialize methods will write/read the Entity value.