Game.Prefabs.Hearse
Assembly:
Game
Namespace:
Game.Prefabs
Type:
class
Base:
ComponentBase
Summary:
Represents the hearse vehicle prefab used by the simulation. Exposes a configurable corpse capacity and supplies the set of ECS components this prefab requires for both prefab creation and entity archetypes. During initialization it writes HearseData to the entity and (when the entity has CarData) sets an UpdateFrameData component to control update frequency.
Fields
public int m_CorpseCapacity = 1
Holds the number of corpses this hearse can carry. Default is 1. This value is written into the entity as a HearseData component in Initialize(EntityManager, Entity). Can be adjusted on the prefab (inspector or code) to change vehicle capacity.
Properties
- This class does not declare any C# properties.
Constructors
public Hearse()
Implicit parameterless constructor. The prefab is typically instantiated by the prefab system; no custom construction behavior is defined in the class itself.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds components that must exist on the prefab entity itself. This implementation adds:- HearseData (ReadWrite) — stores the hearse-specific data (capacity, etc.)
-
UpdateFrameData (ReadWrite) — controls update frequency for the prefab where applicable
-
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds components that should be present when creating runtime archetypes/entities for this prefab. This implementation adds: - Game.Vehicles.Hearse (ReadWrite) — runtime vehicle tag/data for hearse behavior
- Passenger (ReadWrite) — passenger data to allow passenger handling Additionally, if the archetype components already contain Moving (ReadWrite), the method adds:
- PathInformation (ReadWrite) — pathfinding data used while moving
-
ServiceDispatch (ReadWrite) — data used by dispatch/service systems (e.g., corpses pickup)
-
public override void Initialize(EntityManager entityManager, Entity entity)
Writes the runtime component data to the created entity: - Sets HearseData on the entity using the m_CorpseCapacity field.
- If the entity has CarData, sets UpdateFrameData with a value of 11 (controls update timing). This ties prefab configuration into runtime entity setup during instantiation.
Usage Example
// Example: adjusting capacity on a Hearse prefab and initializing it on an entity.
// (In practice the prefab system creates and initializes prefabs; shown here for illustration.)
using Unity.Entities;
using Game.Prefabs;
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
var hearsePrefab = new Hearse { m_CorpseCapacity = 2 };
// Assume 'entity' is created from an appropriate archetype by your prefab system:
Entity entity = em.CreateEntity(/* appropriate archetype */);
// Initialize writes HearseData and optionally UpdateFrameData (if CarData present)
hearsePrefab.Initialize(em, entity);
{{ Additional notes: - The class is annotated with [ComponentMenu("Vehicles/", new Type[] { typeof(CarPrefab) })], which places this prefab under the Vehicles menu and associates it with CarPrefab in the editor/tools that consume this attribute. - The check for the presence of Moving in GetArchetypeComponents is used to avoid adding pathfinding/dispatch components for non-moving archetypes. - UpdateFrameData(11) is used to tune how frequently this entity is updated; the value 11 mirrors the original design choice in the game and may affect performance or responsiveness if changed. }}