Game.Prefabs.ElectricityConnectionData
Assembly:
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents metadata for an electricity connection on a prefab. Holds capacity, flow direction and voltage tier used by the game's electricity connection systems. The struct implements custom binary serialization (Serialize/Deserialize) for saving/loading and networking. Several CompositionFlags fields are present for composition/filtering logic but are not written/read by the current serialization implementation.
Fields
-
public int m_Capacity
Capacity of the electricity connection. Represents the connection's power capacity in the game's internal units (used by simulation and routing). -
public FlowDirection m_Direction
Flow direction for this connection (e.g., Input, Output, Both). Stored/serialized as a single byte. -
public ElectricityConnection.Voltage m_Voltage
Voltage tier for the connection (an enum nested under ElectricityConnection). Stored/serialized as a single byte. -
public CompositionFlags m_CompositionAll
Composition/filter flag: items that must all match. Used by prefab composition/query logic; not serialized by the current Serialize implementation. -
public CompositionFlags m_CompositionAny
Composition/filter flag: any-match semantics. Used by prefab composition/query logic; not serialized by the current Serialize implementation. -
public CompositionFlags m_CompositionNone
Composition/filter flag: none-match semantics. Used by prefab composition/query logic; not serialized by the current Serialize implementation.
Properties
- None (the struct exposes public fields; no C# properties are defined).
Constructors
public ElectricityConnectionData()
Default (compiler-provided) value-type constructor. No custom constructor is defined in source.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component to the provided writer in this exact order:- m_Capacity (int)
- m_Direction (as byte)
- m_Voltage (as byte)
Note: CompositionFlags fields are not written. Because the enums are serialized as bytes, ensure enum values fit into a byte.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component from the reader in the same order used by Serialize:- Reads int into m_Capacity
- Reads a byte and casts to FlowDirection into m_Direction
- Reads a byte and casts to ElectricityConnection.Voltage into m_Voltage
The implementation reads the two enum values as bytes and then assigns them. The composition flag fields remain untouched by deserialization.
Notes and modding guidance: - Maintain the exact read/write order and types for compatibility. If you add new fields, append them at the end and provide versioning or fallbacks to avoid breaking saved data or network messages. - Enums are stored as bytes: if you extend the enum beyond byte range or change underlying values, you must handle compatibility. - CompositionFlags fields are used at runtime for prefab composition/selection but are intentionally not persisted here — if you need them saved, extend the Serialize/Deserialize methods accordingly.
Usage Example
// Example: creating and adding the component to an Entity
var connection = new ElectricityConnectionData {
m_Capacity = 1000,
m_Direction = FlowDirection.Output,
m_Voltage = ElectricityConnection.Voltage.High,
m_CompositionAll = CompositionFlags.None,
m_CompositionAny = CompositionFlags.None,
m_CompositionNone = CompositionFlags.None
};
entityManager.AddComponentData(entity, connection);
// Example: manual serialization (IWriter is the game's writer interface)
connection.Serialize(writer);