Game.Prefabs.NetData
Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
NetData is a lightweight component/serializable container used by the game's ECS prefabs for network (road/rail) prefabs. It holds archetypes used to instantiate node/edge entities, layer bitmasks controlling connectivity and requirements, composition flag masks, and a node priority value. The struct implements ISerializable to persist only a subset of its fields (layer masks and node priority) — archetypes and flag masks are not written by the current implementation. This struct is intended to be attached to prefab entities so systems can query prefab-related net creation parameters.
Fields
-
public EntityArchetype m_NodeArchetype
Used to store the EntityArchetype for node entities created for this net prefab (e.g., junction nodes). This archetype is used at runtime when instantiating node entities. Note: this field is not serialized by Serialize/Deserialize in the shown implementation. -
public EntityArchetype m_EdgeArchetype
Used to store the EntityArchetype for edge entities created for this net prefab (e.g., road segments). Like m_NodeArchetype, this is used at runtime and is not serialized in the current Serialize implementation. -
public Layer m_RequiredLayers
A bitmask (Layer enum) indicating layers that are required/present for this net prefab. This value is serialized (written as a uint) and restored during deserialization. -
public Layer m_ConnectLayers
A bitmask (Layer enum) describing which layers this net can connect to. This value is serialized (written as a uint) and restored during deserialization. -
public Layer m_LocalConnectLayers
A bitmask for local connectivity constraints; serialized (written as a uint) and restored on deserialize. -
public CompositionFlags.General m_GeneralFlagMask
Mask of general composition flags relevant for the prefab. Present for runtime logic/filters but not serialized by the provided methods. -
public CompositionFlags.Side m_SideFlagMask
Mask of side-specific composition flags (e.g., left/right composition) used by runtime logic. Not serialized by the current implementation. -
public float m_NodePriority
Float priority value for node creation/selection. This value is serialized and deserialized.
Properties
- (none)
This struct exposes only public fields; there are no C# properties defined.
Constructors
public NetData()
Default parameterless constructor (value-type default). Default values are the usual struct defaults: archetypes default/empty, enum bitmasks = 0, flags = 0, and m_NodePriority = 0.0f. If specific initialization is required, initialize fields explicitly after construction.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes a subset of the struct to the provided writer: m_RequiredLayers, m_ConnectLayers, m_LocalConnectLayers (each cast to uint), and m_NodePriority (float). The write order is: requiredLayers, connectLayers, localConnectLayers, nodePriority. Archetypes and composition flag masks are not serialized here — they must be initialized by runtime code or other systems if needed after deserialization. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads values in the same order as Serialize wrote them: three uints (for the three Layer fields) and a float (nodePriority). The method assigns the three Layer fields and the node priority. Note: m_GeneralFlagMask, m_SideFlagMask, m_NodeArchetype, and m_EdgeArchetype are not touched by this method and must be set up separately if required.
Usage Example
// Example: initialize a NetData instance for a prefab and write it with a writer.
// TWriter is any implementation of IWriter used by the game's serialization system.
var netData = new NetData();
netData.m_RequiredLayers = Layer.Vehicle | Layer.Pedestrian;
netData.m_ConnectLayers = Layer.Vehicle;
netData.m_LocalConnectLayers = Layer.Vehicle;
netData.m_NodePriority = 1.0f;
// Note: m_NodeArchetype / m_EdgeArchetype should be set up by the prefab creation code.
// Serializing (pseudo-code, replace SomeWriter with the game's writer)
using (var writer = new SomeWriter(stream))
{
netData.Serialize(writer);
}
// Deserializing (pseudo-code)
var loaded = new NetData();
using (var reader = new SomeReader(stream))
{
loaded.Deserialize(reader);
}
// After deserialization, ensure archetypes and flag masks are initialized by the prefab loader/system.
Additional notes: - Maintain the same write/read order when changing Serialize/Deserialize to preserve save compatibility. - Because archetypes and flag masks are not serialized, prefab load paths must recreate or reassign those runtime-only fields.