Skip to content

Game.Prefabs.Resident

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs

Type:
class

Base:
ComponentBase

Summary:
Prefab component used to mark a prefab as a "Resident" creature. It exposes an AgeMask (m_Age) that is written into the entity as ResidentData during conversion and ensures the ECS archetype contains the runtime Game.Creatures.Resident component. Use this component on a GameObject prefab to control which ages the resident can represent; when the prefab is converted to an Entity, Initialize sets the ResidentData component accordingly.


Fields

  • public AgeMask m_Age = AgeMask.Any
    Controls the age category for this resident prefab. The value is copied into the ResidentData component when the prefab is initialized as an Entity. AgeMask is used by the creatures/resident systems to filter or configure behavior for different age groups. Default is AgeMask.Any.

Properties

  • (none)
    This class does not declare any properties. It exposes a public field (m_Age) and overrides ComponentBase methods.

Constructors

  • public Resident()
    No explicit constructor is declared in the source; the default parameterless constructor is used. Initialization of ECS component data occurs in Initialize rather than in a constructor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds ComponentType.ReadWrite() to the provided set. This tells the conversion flow to include ResidentData on the prefab entity so data for age, etc. is available.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds ComponentType.ReadWrite() to the archetype components set. This ensures the runtime ECS archetype contains the Game.Creatures.Resident component (the runtime representation for creature logic).

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called during conversion/initialization of the prefab as an Entity. Calls base.Initialize then sets the ResidentData component on the created entity with the current m_Age value: entityManager.SetComponentData(entity, new ResidentData { m_Age = m_Age });

Usage Example

// Set up a Resident component on a GameObject prefab (e.g. in editor or at runtime)
var residentComponent = gameObject.AddComponent<Game.Prefabs.Resident>();
residentComponent.m_Age = AgeMask.Adult;

// During prefab -> entity conversion the system will call:
// residentComponent.GetPrefabComponents(...)  -> ensures ResidentData exists
// residentComponent.GetArchetypeComponents(...) -> ensures Game.Creatures.Resident exists
// residentComponent.Initialize(entityManager, entity) -> writes ResidentData with m_Age