Game.Zones.SubBlock
Assembly: Assembly-CSharp
Namespace: Game.Zones
Type: struct
Base: IBufferElementData, IEquatable
Summary:
Represents a lightweight buffer element that holds a reference to a sub-block Entity used by the zone/block system. The struct is intended to be stored in a Unity.Entities.DynamicBuffer
Fields
public Unity.Entities.Entity m_SubBlock
Holds the Entity reference for the sub-block. This is the value used for equality and hashing. The field is public for direct, low-overhead access within ECS systems and jobs.
Properties
- This type defines no properties. Interaction is performed via the public m_SubBlock field.
Constructors
public SubBlock(Unity.Entities.Entity block)
Creates a new SubBlock wrapping the provided Entity. Use this when adding elements to a DynamicBufferor when creating struct instances directly.
Methods
-
public bool Equals(SubBlock other)
Compares this instance to another SubBlock by delegating to Entity.Equals on the contained m_SubBlock. Returns true if both reference the same Entity. -
public override int GetHashCode()
Returns the hash code of the contained Entity (m_SubBlock.GetHashCode()). Useful when SubBlock instances are used in hashed containers or compared.
Additional notes: - The struct implements IEmptySerializable to support the game's/custom serialization systems; no serialization-specific members are present here because the serialization marker is handled by the interface and surrounding framework. - The attribute [InternalBufferCapacity(4)] configures the default inline capacity of the dynamic buffer for small-size optimization (4 elements) before additional memory is allocated.
Usage Example
// Example: Adding a sub-block entity into a DynamicBuffer<SubBlock>
using Unity.Entities;
using Game.Zones;
public void AddSubBlock(EntityManager em, Entity parentEntity, Entity subBlockEntity)
{
// Ensure the parent has the DynamicBuffer<SubBlock> — typically via a component that provides the buffer
if (!em.HasComponent<SubBlock>(parentEntity))
{
em.AddBuffer<SubBlock>(parentEntity);
}
var buffer = em.GetBuffer<SubBlock>(parentEntity);
buffer.Add(new SubBlock(subBlockEntity));
// Later: compare two SubBlock entries
var first = buffer[0];
bool isSame = first.Equals(new SubBlock(subBlockEntity)); // true
}
{{ Additional info: Use this struct anywhere you need to store or pass references to sub-block Entities inside ECS buffers. Access the m_SubBlock field directly in jobs or systems for minimal overhead. Remember that Entity equality compares entity id and version — if an entity is destroyed and its id reused, comparisons may behave accordingly. }}