Skip to content

Game.Prefabs.VehiclePrefab

Assembly: Assembly-CSharp (game code)
Namespace: Game.Prefabs

Type: public abstract class

Base: MovingObjectPrefab

Summary:
VehiclePrefab is an abstract prefab base class for vehicle-type moving objects. It extends MovingObjectPrefab and contributes the vehicle-specific Entity Component System (ECS) components used by the game. In GetPrefabComponents it registers vehicle-related prefab data (VehicleData). In GetArchetypeComponents it registers runtime/archetype components required on spawned vehicle entities (Vehicle, Color, Surface). All added component types are added as read/write ComponentType entries. These methods call the base implementations, so derived classes should call base when overriding to preserve base behavior.


Fields

  • None declared in this class.
    This class does not declare any private or public fields; any state comes from the base MovingObjectPrefab or from components added to entities.

Properties

  • None declared in this class.
    Component configuration is exposed via the overridden methods rather than properties.

Constructors

  • public VehiclePrefab()
    Default parameterless constructor (generated by the compiler). The class is abstract so it cannot be instantiated directly; derived prefabs will call this constructor implicitly.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds prefab-level components required by vehicle prefabs. Implementation calls the base GetPrefabComponents(components) and then adds:
  • ComponentType.ReadWrite()

Notes: - The HashSet is used to avoid duplicate entries. - VehicleData typically contains configuration/state data used when creating vehicle entities.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds archetype/runtime components required on vehicle entities. Implementation calls the base GetArchetypeComponents(components) and then adds:
  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite()

Notes: - These components represent the runtime data each vehicle entity requires (logic/identification, visual color, surface interaction). - All are added as ReadWrite so systems can read and modify them.

Usage Example

// Example of a concrete vehicle prefab that adds an extra component
namespace Game.Prefabs
{
    public class CarPrefab : VehiclePrefab
    {
        public override void GetPrefabComponents(HashSet<ComponentType> components)
        {
            base.GetPrefabComponents(components);
            components.Add(ComponentType.ReadWrite<CarData>());
        }

        public override void GetArchetypeComponents(HashSet<ComponentType> components)
        {
            base.GetArchetypeComponents(components);
            components.Add(ComponentType.ReadWrite<Car>());
        }
    }
}

Notes and tips: - Always call base.GetPrefabComponents / base.GetArchetypeComponents from overrides to preserve the base component set. - Use ComponentType.ReadWrite() to register components that systems will both read and write. - Keep component lists minimal and focused to avoid bloated archetypes and extra memory overhead.