Skip to content

Game.Simulation.ElectricityBuildingConnection

Assembly: Assembly-CSharp.dll
Namespace: Game.Simulation

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents the electrical connection information for a building in the electricity simulation. The struct stores references to a transformer node and several electricity flow edges (producer, consumer, charge, discharge). Helper methods resolve the actual node Entity at the ends of those edges using a ComponentLookup. The type also implements a simple binary serialization/deserialization pair via ISerializable so it can be saved/loaded with entity references preserved.


Fields

  • public Unity.Entities.Entity m_TransformerNode
    Holds the Entity reference for the transformer's node associated with this building.

  • public Unity.Entities.Entity m_ProducerEdge
    Entity reference to the electricity flow edge that acts as the producer edge. Use GetProducerNode to resolve the actual node Entity at that edge's end.

  • public Unity.Entities.Entity m_ConsumerEdge
    Entity reference to the electricity flow edge that acts as the consumer edge. Use GetConsumerNode to resolve the actual node Entity at that edge's start.

  • public Unity.Entities.Entity m_ChargeEdge
    Entity reference to the electricity flow edge used for charging (e.g., batteries). Use GetChargeNode to resolve the node at that edge's start.

  • public Unity.Entities.Entity m_DischargeEdge
    Entity reference to the electricity flow edge used for discharging. Use GetDischargeNode to resolve the node at that edge's end.

Properties

  • This type does not declare any properties.

Constructors

  • public ElectricityBuildingConnection()
    Implicit default value-type constructor. All Entity fields default to Entity.Null unless explicitly set.

Methods

  • public Entity GetProducerNode(ref ComponentLookup<ElectricityFlowEdge> flowEdges)
    Returns the node Entity at the producer edge's end by looking up the ElectricityFlowEdge component on m_ProducerEdge and returning its m_End field.

  • public Entity GetConsumerNode(ref ComponentLookup<ElectricityFlowEdge> flowEdges)
    Returns the node Entity at the consumer edge's start by looking up the ElectricityFlowEdge component on m_ConsumerEdge and returning its m_Start field.

  • public Entity GetChargeNode(ref ComponentLookup<ElectricityFlowEdge> flowEdges)
    Returns the node Entity used for charging by looking up the ElectricityFlowEdge component on m_ChargeEdge and returning its m_Start field.

  • public Entity GetDischargeNode(ref ComponentLookup<ElectricityFlowEdge> flowEdges)
    Returns the node Entity used for discharging by looking up the ElectricityFlowEdge component on m_DischargeEdge and returning its m_End field.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes each Entity field (transformer node and the four edges) to the provided writer in sequence. This is used to persist the connection's entity references.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads each Entity field back from the provided reader in the same order they were written. Restores the connection's entity references when loading.

Remarks: - The Get*Node methods expect a valid ComponentLookup that contains the ElectricityFlowEdge component for the edge entities referenced in this struct. Accessing an edge that does not exist or is invalid will cause undefined behavior. - This struct is a plain data container meant to be used as an ECS component (IComponentData). It is suitable for storing entity references and performing lookups in systems that have read access to ElectricityFlowEdge components.

Usage Example

// Example inside a system where you have a ComponentLookup<ElectricityFlowEdge> flowEdges (read access)
public void SomeSystemMethod(ElectricityBuildingConnection connection, ref ComponentLookup<ElectricityFlowEdge> flowEdges)
{
    // Get the actual node entities for various purposes
    Entity producerNode = connection.GetProducerNode(ref flowEdges);
    Entity consumerNode = connection.GetConsumerNode(ref flowEdges);
    Entity chargeNode = connection.GetChargeNode(ref flowEdges);
    Entity dischargeNode = connection.GetDischargeNode(ref flowEdges);

    // Example check (ensure nodes are valid before using)
    if (producerNode != Entity.Null)
    {
        // Do something with producerNode...
    }
}

// Serialization example (writer provided by the game's serialization infrastructure)
connection.Serialize(writer);

// Deserialization example
connection.Deserialize(reader);