Game.Prefabs.CitizenData
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter
Summary:
CitizenData is a lightweight ECS component used by the game's DOTS-based systems to represent the gender of a citizen. It is a plain value type (struct) implementing IComponentData so it can be attached to entities and used in jobs and Entity queries. It also implements IQueryTypeParameter (a marker interface used by the modding/game query tooling) to allow the type to be used directly in query/type-parameter contexts.
Notes:
- Because this is a small, blittable component, it is efficient to store on many entities.
- Be aware that C# bool sizing/packing can vary; if you need explicit control over memory layout or serialization, consider using a byte or int field instead of bool.
Fields
public System.Boolean m_Male
Indicates the citizen's gender. True = male, False = female. Default value (when not set) is false. This field is the single piece of data carried by the component and can be read/modified in systems or jobs.
Properties
- This type defines no properties.
Constructors
- The struct has the compiler-generated default (parameterless) constructor.
You can construct instances inline when setting component data, e.g.new CitizenData { m_Male = true }
.
Methods
- This type defines no methods.
Usage Example
using Unity.Entities;
using Game.Prefabs;
// Creating an entity and adding the component
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = entityManager.CreateEntity(typeof(CitizenData));
entityManager.SetComponentData(e, new CitizenData { m_Male = true });
// Reading/modifying inside a SystemBase
public partial class CitizenExampleSystem : SystemBase
{
protected override void OnUpdate()
{
Entities.ForEach((ref CitizenData citizen) =>
{
if (citizen.m_Male)
{
// do male-specific logic
}
else
{
// do female-specific logic
}
// Example: toggle gender (for demonstration)
// citizen.m_Male = !citizen.m_Male;
}).Schedule();
}
}