Game.Prefabs.PersonalCar
Assembly:
Assembly-CSharp (game/mod assembly)
Namespace:
Game.Prefabs
Type:
class
Base:
ComponentBase
Summary:
PersonalCar is a prefab component used to configure personal car vehicle prefabs. It exposes editable fields for passenger and baggage capacities, drive cost and spawn probability. At authoring time it declares which ECS components are required on the prefab/archetype and writes a PersonalCarData component to the entity when initialized. The class is annotated with ComponentMenu so it appears under Vehicles in the editor.
Fields
-
public int m_PassengerCapacity = 5
Configurable passenger capacity for the vehicle. Default value 5. This value is copied into the runtime PersonalCarData component during Initialize. -
public int m_BaggageCapacity = 5
Configurable baggage capacity for the vehicle. Default value 5. Copied to PersonalCarData on Initialize. -
public int m_CostToDrive = 8
Cost (game units) to drive this vehicle. Default value 8. Copied to PersonalCarData on Initialize. -
[Range(0f, 100f)] public int m_Probability = 100
Spawn/selection probability (0–100). The Range attribute controls editor slider limits. Default is 100. Copied to PersonalCarData on Initialize.
Properties
- None declared on this class. The class exposes data via public fields and writes a runtime PersonalCarData component.
Constructors
public PersonalCar()
No explicit constructor is defined in code; the default parameterless constructor is used. Initialization of default field values occurs via field initializers shown above.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the prefab-level ECS components required on the prefab entity. This implementation adds ComponentType.ReadWrite() so the prefab entity contains the PersonalCarData component. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds components required for the runtime archetype used when instantiating this prefab. This implementation adds: - ComponentType.ReadWrite
() - ComponentType.ReadWrite
()
(These must correspond to existing ECS component types/structs in the game.)
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab entity is initialized. This method writes a new PersonalCarData instance to the entity using the values from the inspector-exposed fields:- m_PassengerCapacity
- m_BaggageCapacity
- m_CostToDrive
- m_Probability
It uses entityManager.SetComponentData(entity, new PersonalCarData { ... }).
Usage Example
[Preserve]
public class MyCustomCarPrefab : PersonalCar
{
// You can override defaults in code if needed:
public MyCustomCarPrefab()
{
m_PassengerCapacity = 4;
m_BaggageCapacity = 2;
m_CostToDrive = 10;
m_Probability = 80;
}
// Initialization is handled by PersonalCar.Initialize which writes
// PersonalCarData to the entity. If you need custom setup, override:
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
// additional custom component setup here
}
}
Notes and dependencies: - This class relies on a PersonalCarData struct/component type (written in Initialize). Ensure the PersonalCarData definition exists and matches the fields assigned here. - The archetype components reference Game.Vehicles.PersonalCar and Passenger component types — those must be present in the project. - The [ComponentMenu] attribute places this prefab under Vehicles in the editor and lists related prefab types (CarPrefab, CarTrailerPrefab).