Skip to content

Game.Prefabs.WatercraftPrefab

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: VehiclePrefab

Summary:
Defines a vehicle prefab for watercraft (ships) used by the ECS prefab/authoring system. Exposes editable design parameters (size class, energy type, speed/acceleration/braking, turning and angular acceleration) and populates runtime ECS components (WatercraftData, UpdateFrameData) when the prefab is initialized. Also augments archetype components to include navigation/pathfinding-related components when the prefab supports movement.


Fields

  • public SizeClass m_SizeClass = SizeClass.Large
    Default size class for the watercraft. Used to initialize WatercraftData.m_SizeClass.

  • public EnergyTypes m_EnergyType = EnergyTypes.Fuel
    Energy/fuel type used by the watercraft, assigned to WatercraftData.m_EnergyType.

  • public float m_MaxSpeed = 150f
    Maximum speed value in the prefab (expressed in the inspector units, converted to m/s in Initialize by dividing by 3.6). Assigned to WatercraftData.m_MaxSpeed.

  • public float m_Acceleration = 1f
    Acceleration parameter assigned to WatercraftData.m_Acceleration.

  • public float m_Braking = 2f
    Braking parameter assigned to WatercraftData.m_Braking.

  • public float2 m_Turning = new float2(30f, 5f)
    Two-component turning parameter (default values are in degrees in the prefab). Converted to radians in Initialize and stored in WatercraftData.m_Turning. The precise semantic interpretation (e.g., yaw vs. roll or primary/secondary turning rates) is defined by WatercraftData/vehicle systems.

  • public float m_AngularAcceleration = 5f
    Angular acceleration expressed in degrees in the prefab; converted to radians in Initialize and stored in WatercraftData.m_AngularAcceleration.

Properties

  • public override IEnumerable<string> modTags { get; }
    Returns the base prefab mod tags plus an additional "Ship" tag. Useful for mod indexing/filtering and tooling that relies on prefab tags.

Constructors

  • public WatercraftPrefab()
    Default parameterless constructor (no custom construction logic in source; default field values are used).

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds component types that should be present (read/write) on entities authored from this prefab. This override calls the base implementation and then adds:
  • WatercraftData (read/write)
  • UpdateFrameData (read/write)

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds components to the archetype used for entities created from this prefab. Calls the base implementation and adds:

  • Watercraft (read/write) If the archetype contains Moving (read/write), it also adds navigation/pathfinding related components:
  • WatercraftNavigation
  • WatercraftNavigationLane
  • WatercraftCurrentLane
  • PathOwner
  • PathElement
  • Target
  • Blocker

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Initializes ECS component data on the given entity from the prefab fields. Implementation details:

  • Builds a WatercraftData struct and sets:
    • m_SizeClass from m_SizeClass
    • m_EnergyType from m_EnergyType
    • m_MaxSpeed from m_MaxSpeed / 3.6f (converts inspector km/h → m/s)
    • m_Acceleration from m_Acceleration
    • m_Braking from m_Braking
    • m_Turning from math.radians(m_Turning) (converts degrees → radians)
    • m_AngularAcceleration from math.radians(m_AngularAcceleration)
  • Writes WatercraftData to the entity via EntityManager.SetComponentData
  • Writes an UpdateFrameData(8) component to the entity via EntityManager.SetComponentData

Notes: - The class is decorated with [ComponentMenu("Vehicles/", new Type[] { })], placing it in the Vehicles component menu in authoring tools. - Conversions: m_MaxSpeed is converted by dividing by 3.6f; angles (m_Turning, m_AngularAcceleration) are converted from degrees to radians using math.radians.

Usage Example

public override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);

    WatercraftData componentData = default(WatercraftData);
    componentData.m_SizeClass = m_SizeClass;
    componentData.m_EnergyType = m_EnergyType;
    // Prefab m_MaxSpeed is in km/h (or inspector units); convert to m/s:
    componentData.m_MaxSpeed = m_MaxSpeed / 3.6f;
    componentData.m_Acceleration = m_Acceleration;
    componentData.m_Braking = m_Braking;
    // Turning and angular acceleration are specified in degrees in the prefab:
    componentData.m_Turning = math.radians(m_Turning);
    componentData.m_AngularAcceleration = math.radians(m_AngularAcceleration);

    entityManager.SetComponentData(entity, componentData);
    // Configure update frame frequency/offset:
    entityManager.SetComponentData(entity, new UpdateFrameData(8));
}