Game.Creatures.HumanNavigation
Assembly:
Assembly-CSharp (inferred)
Namespace:
Game.Creatures
Type:
struct (IComponentData, IQueryTypeParameter, ISerializable)
Base:
System.ValueType
Summary:
HumanNavigation is an ECS component used to store navigation and simple animation/activity state for human/creature entities. It contains target position/direction, movement speed and a couple of activity/state bytes, and implements custom binary serialization to support save/load across game versions. The component is intended for use with Unity.Entities queries and systems that drive creature movement and activity.
Fields
-
public float3 m_TargetPosition
Holds the world-space target position the human is navigating toward. Serialized first in the component's binary representation. -
public float2 m_TargetDirection
Holds the 2D direction toward the target (usually normalized XZ or XY depending on convention). This field is conditionally serialized/read depending on save version (see Version.creatureTargetDirection). -
public float m_MaxSpeed
Maximum movement speed for the human. Serialized last in the component's data layout. -
public TransformState m_TransformState
Compact enum/state describing transform/animation state. When serialized this is written/read as a byte. Reading behavior changed in newer save versions (see Version.animationStateFix). -
public byte m_LastActivity
A small enum/flag byte representing the last activity the human performed. The serialized position relative to TransformState is version-dependent (see Deserialize logic). -
public byte m_TargetActivity
A small enum/flag byte representing the target activity the human should perform when arriving at the target. This is only present in saves at or above Version.creatureTargetDirection.
Properties
- This type defines no properties.
Constructors
public HumanNavigation()
Implicit default value-type constructor. Fields are default-initialized; use explicit initialization when adding the component to an entity.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component fields to a binary writer in a specific order:- m_TargetPosition (float3)
- m_TargetDirection (float2)
- m_TargetActivity (byte)
- m_TransformState as byte
- m_LastActivity (byte)
-
m_MaxSpeed (float)
Note: The method writes TransformState as a byte and expects the reader to interpret it accordingly. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads component data from a binary reader with version checks to maintain compatibility: - Always reads m_TargetPosition first.
- If reader.context.version >= Version.creatureTargetDirection, reads m_TargetDirection and m_TargetActivity.
- If reader.context.version >= Version.animationStateFix, reads a byte (interpreted as TransformState), then reads m_LastActivity and assigns m_TransformState from that first byte value. This handles an older layout/bugfix where ordering/meaning of those bytes changed.
- Finally reads m_MaxSpeed.
Be aware of these version-dependent paths when extending or modifying serialization behavior to avoid breaking saved data compatibility.
Usage Example
// Example: adding and initializing the HumanNavigation component on an entity
using Unity.Entities;
using Unity.Mathematics;
using Game.Creatures;
public static class HumanHelpers
{
public static void AddHumanNavigation(EntityManager em, Entity e, float3 targetPos)
{
var nav = new HumanNavigation
{
m_TargetPosition = targetPos,
m_TargetDirection = new float2(0f, 0f), // set by movement system
m_MaxSpeed = 2.0f,
m_TransformState = TransformState.Idle, // example enum value
m_LastActivity = 0,
m_TargetActivity = 0
};
em.AddComponentData(e, nav);
}
}
Notes: - The struct implements ISerializable to participate in the game's custom save/load pipeline; preserve careful ordering and version checks when changing fields. - As an IComponentData it is intended to be used with Unity.Entities systems and queries.