Game.Prefabs.TrainCarPrefab
Assembly:
Namespace: Game.Prefabs
Type: class
Base: TrainPrefab
Summary:
TrainCarPrefab is a Unity ECS prefab class used to declare which components belong to a train car prefab. It is annotated with a ComponentMenu attribute ("Vehicles/") so it appears in the editor menu. The class overrides GetPrefabComponents to add the TrainCarriageData component (read/write) to the prefab's component set, ensuring entities created from this prefab include the carriage data required by train logic.
Fields
- This class does not declare any private or public fields.
No instance fields are defined in the source; it relies on inherited behavior from TrainPrefab.
Properties
- This class does not declare any properties.
All relevant data is provided via components added in GetPrefabComponents and via the base class.
Constructors
public TrainCarPrefab()
No explicit constructors are declared; the default parameterless constructor is used.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Overrides the base prefab registration method. Calls the base implementation and then adds ComponentType.ReadWrite() to the provided HashSet, which ensures the TrainCarriageData IComponentData is part of the prefab's archetype and is writable on created entities.
Notes:
- TrainCarriageData must be an ECS component type (IComponentData or similar).
- ComponentType.ReadWrite
Usage Example
using System;
using System.Collections.Generic;
using Unity.Entities;
namespace Game.Prefabs;
[ComponentMenu("Vehicles/", new Type[] { })]
public class TrainCarPrefab : TrainPrefab
{
public override void GetPrefabComponents(HashSet<ComponentType> components)
{
base.GetPrefabComponents(components);
components.Add(ComponentType.ReadWrite<TrainCarriageData>());
}
}
Additional information: - This prefab class is intended for use with the game's entity prefab pipeline. When the prefab is converted to an entity archetype, the TrainCarriageData component will be included automatically. - If TrainCarriageData contains fields that must be initialized, initialization typically happens during conversion or when the entity is instantiated from the prefab.