Skip to content

Game.Prefabs.WaterwayPrefab

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: NetGeometryPrefab

Summary:
Prefab class that defines the component composition and archetype components for waterway net prefabs (ships/boats routes, waterways). It exposes a configurable speed limit and ensures the appropriate runtime components are added to entities created from this prefab (e.g., waterway-specific data, lane data and visual/update components). This class is intended to be used by the net/prefab pipeline when creating waterway network entities and their archetypes in the ECS.


Fields

  • public float m_SpeedLimit = 200f
    Configurable speed limit for this waterway prefab. This value is intended to represent the maximum allowed speed on the waterway and can be adjusted in the prefab inspector or by mod code. Default value in source is 200f.

Properties

  • None declared on this type. All behavior is exposed via fields and overridden methods.

Constructors

  • public WaterwayPrefab()
    No explicit constructor is defined in source; the default parameterless constructor is used. Initialization is handled by the base class and by Unity/serialization when the prefab is created/loaded.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Overrides NetGeometryPrefab.GetPrefabComponents to add component types required for a waterway prefab. Calls base implementation and then ensures:
  • WaterwayData (read/write) is added (holds waterway-specific configuration/state).
  • DefaultNetLane (read/write) is added (defines default lane properties for the net). Use: The ECS prefab builder uses this method to collect component types that should be present on instantiated prefab entities.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Overrides NetGeometryPrefab.GetArchetypeComponents to add archetype-specific components based on which core component is present in the provided set:

  • If Edge is present: adds UpdateFrame, EdgeColor, Waterway.
  • Else if Node is present: adds UpdateFrame, NodeColor, Waterway.
  • Else if NetCompositionData is present: adds WaterwayComposition. This method augments the archetype component set used to create entity archetypes for edges, nodes, and composition entities associated with this net prefab. It calls the base implementation first.

Usage Example

// Example: extend the waterway prefab to add a custom component and change the speed limit
[ComponentMenu("Net/Prefab/CustomWaterway", new Type[] { })]
public class CustomWaterwayPrefab : WaterwayPrefab
{
    public float customSpeed = 120f;

    public override void GetPrefabComponents(HashSet<ComponentType> components)
    {
        base.GetPrefabComponents(components);
        // Add a custom component type to entities created from this prefab
        components.Add(ComponentType.ReadWrite<MyCustomWaterwayComponent>());
    }

    public override void GetArchetypeComponents(HashSet<ComponentType> components)
    {
        base.GetArchetypeComponents(components);
        // Additional archetype adjustments can go here
    }

    // You can also set m_SpeedLimit in code (or via the inspector)
    void Awake()
    {
        m_SpeedLimit = customSpeed;
    }
}

Notes for modders: - GetPrefabComponents is used by the prefab-to-entity conversion process to decide which components to include on prefab instances; adding/removing component types here changes the resulting entity composition. - GetArchetypeComponents is used to decide the archetype for different parts of the net (edges, nodes, composition). Be careful to keep compatibility with base behavior when extending; call base implementations unless you intentionally replace the defaults. - m_SpeedLimit is serialized on the prefab and can be tweaked in the inspector or at runtime before the prefab is instantiated.