Game.Prefabs.NetPiecePrefab
Assembly: Assembly-CSharp (inferred)
Namespace: Game.Prefabs
Type: class
Base: RenderPrefab
Summary:
NetPiecePrefab is a prefab class used by the game to describe a "network piece" (a segment of net-type assets such as road/rail pieces). It exposes configuration used by the rendering and ECS systems: physical dimensions (width/length/height range), connection offsets, layer grouping and per-corner surface height adjustments. The prefab participates in the game's Entity Component System by registering required component types (NetPieceData and MeshMaterial) and, during LateInitialize, ensuring that LOD mesh entities have a MeshMaterial component buffer so the rendering/material data can be attached.
Fields
-
public NetPieceLayer m_Layer
The layer/grouping used by the network piece. NetPieceLayer typically defines categories or rendering/interaction layers for network pieces (for example, determining which tool or system affects the piece). -
public float m_Width = 3f
The nominal width of the piece (world units). Used for rendering, physics and snapping calculations. -
public float m_Length = 64f
The nominal length of the piece (world units). Defines how long the segment is, used by placement and LOD logic. -
public Bounds1 m_HeightRange = new Bounds1(0f, 3f)
Allowed height range (min/max) for the piece; a Bounds1 structure (single dimension) representing vertical placement limits or allowable elevation variation. -
public float m_WidthOffset
Offset applied laterally to the piece geometry from its centerline. Useful for adjusting alignment or to create separated lanes/offsets. -
public float m_NodeOffset = 0.5f
Offset applied at nodes (ends) of the piece. Commonly used to push endpoints slightly into/away from the node for correct connection visuals. -
public float m_SideConnectionOffset
Offset used when connecting side elements (e.g., sidewalks or side meshes) to the main piece geometry. -
public float4 m_SurfaceHeights = 0f
Per-corner surface height adjustments expressed as a float4 (likely for the four corners of a quad). These allow small tweaks to the top surface height on a per-corner basis to avoid z-fighting or better follow terrain.
Notes: - All these public fields are editable on the prefab instance (in editor or via code) and affect how the piece is constructed, rendered and connected at runtime.
Properties
- None declared on this class.
Constructors
public NetPiecePrefab()
Default parameterless constructor (inherits default construction behavior from RenderPrefab). The prefab is expected to be initialized by the prefab system; manual construction is uncommon in normal mod scenarios.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Overrides the base method to register ECS component types this prefab requires. It calls base.GetPrefabComponents(...) and then adds:- ComponentType.ReadWrite
() -
ComponentType.ReadWrite
() This ensures entities created for this prefab will include the network piece data and a MeshMaterial buffer for material/mesh-binding data. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Called late in prefab/entity initialization. Behavior: - Calls base.LateInitialize(entityManager, entity).
- Tries to obtain a LodProperties component (via TryGet
); if no LodProperties or its m_LodMeshes is null, it returns early. - Obtains the PrefabSystem for the current World via entityManager.World.GetOrCreateSystemManaged
(). - Iterates over the LodProperties.m_LodMeshes array, gets each mesh prefab's Entity using PrefabSystem.GetEntity(...), and ensures each mesh Entity has a MeshMaterial component buffer:
- If the mesh Entity does not have a MeshMaterial buffer, it adds one via entityManager.AddComponent
(meshEntity). This guarantees that every LOD mesh entity is reachable for material assignments and rendering setup.
- If the mesh Entity does not have a MeshMaterial buffer, it adds one via entityManager.AddComponent
Remarks: - LateInitialize manipulates ECS entities and thus should be run in the appropriate initialization phase (it is invoked by the prefab system). - The method ensures LOD mesh entities are prepared to receive material data even if the original mesh prefab did not explicitly declare MeshMaterial.
Usage Example
// Example: customizing a NetPiecePrefab instance in code before use
NetPiecePrefab myPiece = /* obtain the prefab from PrefabCollection or via serialization */;
myPiece.m_Width = 4.0f;
myPiece.m_Length = 48.0f;
myPiece.m_NodeOffset = 0.6f;
myPiece.m_SurfaceHeights = new float4(0f, 0.02f, 0f, 0.02f);
// When the prefab system initializes entities for this prefab, GetPrefabComponents()
// will ensure NetPieceData and MeshMaterial are registered for the entity,
// and LateInitialize will ensure that all LOD mesh entities have a MeshMaterial buffer
// so materials can be assigned at runtime.
Notes for modders: - If you create custom LOD mesh prefabs referenced by m_LodMeshes, make sure those prefabs either declare a MeshMaterial buffer in their GetPrefabComponents or rely on NetPiecePrefab's LateInitialize to add it. LateInitialize adds MeshMaterial only to the LOD mesh Entities referenced by this NetPiecePrefab. - Changing width/length/offsets affects placement, snapping and visual connections—test pieces in-editor to ensure connection behavior matches expectations. - Bounds1 and float4 types come from Colossal.Mathematics/Unity.Mathematics and should be used consistent with other prefabs in the game for compatibility.