Game.Prefabs.PostVan
Assembly:
Assembly-CSharp (game assembly)
Namespace:
Game.Prefabs
Type:
Class
Base:
ComponentBase
Summary:
PostVan is a prefab component class that configures the mail-delivery vehicle prefab (post/van) for the ECS world. It exposes an editor-settable mail capacity (m_MailCapacity), registers required component types for the prefab and archetype, and initializes the entity with PostVanData and an UpdateFrameData (update slot 9). The class is attributed with ComponentMenu("Vehicles/", typeof(CarPrefab)) so it appears under the Vehicles category in the editor alongside other CarPrefab-derived prefabs.
Fields
public System.Int32 m_MailCapacity
Holds the mail capacity for this vehicle prefab (number of mail items the van can carry). This value is typically set in the prefab inspector and is used when Initialize writes the PostVanData component to the entity.
Properties
- None declared on this class. All configuration is done via the public field(s) and overridden methods.
Constructors
public PostVan()
No explicit constructor is declared in the source; the class uses the default parameterless constructor. Any initialization needed at runtime is performed in Initialize by the engine.
Methods
-
public override void GetPrefabComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
Adds ComponentType.ReadWrite() and ComponentType.ReadWrite () to the provided components set. This tells the prefab builder which components the instantiated entity must include at the prefab level. -
public override void GetArchetypeComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
Adds ComponentType.ReadWrite() to the archetype. Additionally, if the archetype already contains ComponentType.ReadWrite (), it also adds PathInformation and ServiceDispatch component types. This ensures the entity archetype includes pathfinding and service dispatch data when the vehicle is moving. -
public override void Initialize(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity entity)
Writes component data to the created entity: sets PostVanData using the prefab's m_MailCapacity and sets UpdateFrameData with the value 9. This method is called by the prefab instantiation process to populate ECS component state based on the prefab configuration.
Usage Example
// Typical usage: configure the prefab in the editor by setting m_MailCapacity.
// At runtime the engine will call Initialize(entityManager, entity) for each instantiated prefab,
// which writes PostVanData(m_MailCapacity) and UpdateFrameData(9) to the entity.
// Programmatic example (e.g., for tests or custom initialization):
var postVanPrefab = new Game.Prefabs.PostVan();
postVanPrefab.m_MailCapacity = 40; // set desired capacity
// entityManager and entity would normally be provided by the engine/ECS creation flow:
postVanPrefab.Initialize(entityManager, entity);
// After this call, the entity has PostVanData(capacity = 40) and UpdateFrameData(9).
Additional notes: - The class relies on component types and data structs/classes defined elsewhere (PostVanData, UpdateFrameData, Game.Vehicles.PostVan, Moving, PathInformation, ServiceDispatch). - The UpdateFrameData(9) value assigns this prefab/entity to a specific update slot/frame group; consult engine docs to understand how update frame indices affect execution ordering and performance.