Skip to content

Game.Buildings.ConnectedBuilding

Assembly: Game (Assembly-CSharp)
Namespace: Game.Buildings

Type: struct

Base: System.ValueType, Unity.Entities.IBufferElementData, System.IEquatable, Colossal.Serialization.Entities.IEmptySerializable

Summary: Represents a simple buffer element that holds a reference to another building (an Entity) used to record connections between buildings in the ECS world. The struct is intended to be stored in a DynamicBuffer on an entity to track adjacent/linked buildings. The type is marked with [InternalBufferCapacity(0)] to specify no preallocated inline capacity for the dynamic buffer (minimizes per-entity memory when buffers are empty). It also implements IEmptySerializable to support the game's custom serialization system.


Fields

  • public Unity.Entities.Entity m_Building Holds the Entity reference to the connected building. This is the core payload of the buffer element and identifies the other building in the connection.

Properties

  • This type exposes no properties. It uses a public field (m_Building) for its data.

Constructors

  • public ConnectedBuilding(Unity.Entities.Entity building) Initializes a new ConnectedBuilding with the provided Entity. Sets m_Building = building.

Methods

  • public bool Equals(ConnectedBuilding other) Implements IEquatable. Compares the underlying Entity value (m_Building) for equality. Useful when comparing buffer elements or using collections that rely on equality.

  • public override int GetHashCode() Returns the hash code of the contained Entity (m_Building.GetHashCode()). Ensures consistency with the Equals implementation when the struct is used in hashed collections.

Usage Example

// Example: adding a connected building entry to an entity's buffer
// (run inside a SystemBase or where you have access to an EntityManager)

EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity hostEntity = /* the entity that will hold the buffer */;
Entity otherBuildingEntity = /* the connected building entity */;

// Ensure the host has the buffer component
if (!em.HasComponent<DynamicBuffer<ConnectedBuilding>>(hostEntity))
{
    em.AddBuffer<ConnectedBuilding>(hostEntity);
}

// Add the connection
var buffer = em.GetBuffer<ConnectedBuilding>(hostEntity);
buffer.Add(new ConnectedBuilding(otherBuildingEntity));

// Example: check if a connection already exists
bool connected = false;
foreach (var cb in buffer)
{
    if (cb.Equals(new ConnectedBuilding(otherBuildingEntity)))
    {
        connected = true;
        break;
    }
}