Skip to content

Game.Prefabs.CitizenPrefab

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs

Type:
class (public)

Base:
ArchetypePrefab

Summary:
CitizenPrefab is an ArchetypePrefab used by the game's ECS prefab system to create citizen entities. It exposes a simple inspector flag (m_Male) that is written into the CitizenData component when the prefab is initialized, and it registers a set of archetype components required for citizen behavior (trips, crime victim tagging, mail sending, arrival state, car ownership, job seeker flag, and update-frame tag). This prefab is intended to produce entities that represent individual citizens within the simulation and to ensure the entity archetype includes the correct components for citizen systems to operate.


Fields

  • public System.Boolean m_Male
    This public inspector field determines the gender flag written into the CitizenData component for entities created from this prefab. When Initialize is called, the prefab sets CitizenData.m_Male = m_Male. Set this in the prefab asset (Inspector) or at runtime before initialization to control the initial gender state of the resulting citizen entity.

Properties

  • (none)
    This class does not declare any C# properties. All configuration is done via the public field(s) and overridden methods.

Constructors

  • public CitizenPrefab()
    No explicit constructor is declared in the source; the compiler-provided parameterless constructor is used. Initialization logic runs in the overridden Initialize method rather than a constructor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds components that should be present on the prefab "template" itself. This override calls the base implementation and adds ComponentType.ReadWrite() so that the CitizenData component is available to the prefab and can be written during Initialize.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds the set of components that will be included in the entity archetype for each instantiated citizen. This method calls the base implementation and registers the following component types (ReadWrite):

  • Citizen — identifies the entity as a citizen and holds core citizen state.
  • TripNeeded — marks that the citizen needs to make a trip (used by trip planning systems).
  • CrimeVictim — tags the citizen as a potential crime victim (used by crime systems).
  • MailSender — used for mail-sending behavior/systems.
  • Arrived — indicates arrival state for destinations.
  • CarKeeper — contains information about car ownership/usage by the citizen.
  • HasJobSeeker — flag used by job-seeking systems.
  • UpdateFrame — a tag component used to mark entities that need per-frame updates or scheduling.

These components together define the runtime capabilities and systems that will process the citizen entity.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called to initialize an entity instance created from this prefab. This override first calls the base.Initialize, then writes the CitizenData component on the entity, copying the prefab's m_Male field into the component:
  • entityManager.SetComponentData(entity, new CitizenData { m_Male = m_Male });

This ensures the instantiated citizen entity's CitizenData.m_Male reflects the prefab configuration.

Usage Example

// Example: After you obtain a CitizenPrefab asset and instantiate its entity,
// Initialize will copy the prefab.m_Male into the entity's CitizenData component.

// Pseudocode sketch (actual API for obtaining/instantiating a prefab entity may vary):
CitizenPrefab prefab = /* get prefab asset from resources or inspector */;
prefab.m_Male = true; // set in code or via Inspector

// Instantiate the prefab's archetype entity (API for this is game-specific):
Entity instance = entityManager.Instantiate(prefabArchetypeEntity);

// Initialize the instance from the prefab so CitizenData.m_Male is set
prefab.Initialize(entityManager, instance);

// Read back the component to verify
CitizenData data = entityManager.GetComponentData<CitizenData>(instance);
// data.m_Male == true (matches prefab.m_Male)

Additional notes: - This class depends on Unity.Entities (ECS) and game-specific component types such as CitizenData, Citizen, TripNeeded, etc. Make sure those types are available via the game's assemblies and appropriate using directives. - The prefab typically is authored as a Unity asset and used by the prefab/archetype creation pipeline rather than instantiated directly in gameplay scripts; the example above is a simplified illustration of the data flow during initialization.