Game.Prefabs.HumanPrefab
Assembly: Assembly-CSharp (typical Unity project / mod assembly - adjust if your project uses a different assembly)
Namespace: Game.Prefabs
Type: class
Base: CreaturePrefab
Summary:
HumanPrefab defines a creature prefab for human-type agents. It exposes editable speed and acceleration fields (used as default values in the editor) and registers the required ECS components for humans so an Entity archetype can be created. During initialization it writes a HumanData component to the entity, converting inspector speed values (km/h) to meters per second (division by 3.6). The class is intended to be used as part of the game's prefab system to spawn/instantiate human agents and set up their ECS components and runtime data.
Fields
-
public float m_WalkSpeed = 6f
Default walking speed exposed on the prefab. Value in the prefab is expressed in km/h; Initialize converts it to m/s (m_WalkSpeed / 3.6f) when writing HumanData. -
public float m_RunSpeed = 12f
Default running speed exposed on the prefab. Also expressed in km/h and converted to m/s during Initialize. -
public float m_Acceleration = 8f
Default acceleration value (units are game-specific; the class writes it directly into HumanData without unit conversion).
Properties
- This class does not declare properties. It exposes public fields for inspector use and uses ECS components for runtime data.
Constructors
public HumanPrefab()
No explicit constructor is declared in the source; the default parameterless constructor is used. Prefab-specific initialization is done via the overridden Initialize method rather than a constructor (typical for Unity/Entity workflows).
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the prefab-level component types required when the prefab is registered. This override calls the base implementation and then addsComponentType.ReadWrite<HumanData>()
so that HumanData will be available for entities created from this prefab. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds the runtime archetype components needed for human entities. After calling the base implementation it adds the following read/write component types: Human
HumanNavigation
Queue
PathOwner
PathElement
Target
-
Blocker
These components set up navigation/pathfinding, queuing and target/blocker systems required for human agents. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called to initialize a concrete entity instance from the prefab. It calls the base.Initialize and then sets theHumanData
component on the created entity with values derived from the prefab fields: - m_WalkSpeed is converted from km/h to m/s by dividing by 3.6f
- m_RunSpeed is converted the same way
- m_Acceleration is written directly Uses EntityManager.SetComponentData to write the HumanData struct to the entity.
Usage Example
// Example: customize a human prefab before initialization or extend it.
public class FastHumanPrefab : HumanPrefab
{
public override void Initialize(EntityManager entityManager, Entity entity)
{
// Adjust prefab defaults (these will be converted in base.Initialize)
m_WalkSpeed = 10f; // km/h in the prefab inspector units
m_RunSpeed = 20f; // km/h
m_Acceleration = 12f;
base.Initialize(entityManager, entity);
}
}
Notes and tips:
- The prefab stores speeds in km/h for the inspector fields; Initialize converts speeds to m/s because the runtime HumanData expects SI units.
- The component registration methods use Unity.Entities.ComponentType.ReadWrite