Skip to content

Game.Prefabs.ServicePrefab

Assembly:
Assembly-CSharp (Game) — likely contained in the game's main assembly (Assembly-CSharp.dll).
Namespace: Game.Prefabs

Type:
public class ServicePrefab : PrefabBase

Base:
PrefabBase

Summary:
ServicePrefab is a Unity component (prefab behaviour) used to configure ECS components for a city "service" prefab (e.g., police, fire, utilities) at prefab initialization time. It exposes inspector-settable fields for which city resources the service should collect fees from, which CityService this prefab represents, and whether its budget is adjustable. At entity initialization it ensures the proper ECS components/buffers are present and populates ServiceData and any CollectedCityServiceFeeData entries based on the configured resources.


Fields

  • private PlayerResource[] m_CityResources
    Array of PlayerResource values indicating which city resources this service collects fees for. If non-null and non-empty, the prefab will add a CollectedCityServiceFeeData buffer and populate one entry per resource.

  • private CityService m_Service
    Enum (or struct) value identifying the specific city service represented by this prefab (e.g., police, fire). This value is stored in the ServiceData component on the created entity.

  • private bool m_BudgetAdjustable = true
    Flag indicating whether the service’s budget can be adjusted. This value is stored in the ServiceData component (m_BudgetAdjustable).

Properties

  • (None declared in this class)

Constructors

  • public ServicePrefab()
    Default constructor (no custom initialization in source). Instances are typically created/used by the Unity editor when placing prefabs.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Overrides PrefabBase.GetPrefabComponents to declare the ECS component types that this prefab requires:
  • Always adds: ServiceData, CollectedCityServiceBudgetData, CollectedCityServiceUpkeepData.
  • Adds CollectedCityServiceFeeData if m_CityResources is non-null and contains entries. This method informs the entity conversion system which component types should be present on the entity representing the prefab.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Overrides PrefabBase.LateInitialize to populate runtime component data on the created entity:

  • If m_CityResources is non-null/non-empty, obtains the DynamicBuffer from the entity and adds an entry for each configured PlayerResource setting m_PlayerResource to the integer value of the enum.
  • Sets the ServiceData component on the entity with m_Service and m_BudgetAdjustable. Note: This method assumes the appropriate buffer/component types were declared in GetPrefabComponents so the buffer exists.

Additional notes: - The class is decorated with [ComponentMenu("Services/", new Type[] { })], which organizes it under "Services/" in Unity’s Add Component menu. - Requires Unity.Entities (ECS) types and Game.City / Game.Simulation domain types.

Usage Example

// This example demonstrates what LateInitialize will do at entity creation.
// Assume a prefab in the editor has:
//   m_CityResources = [PlayerResource.Tax, PlayerResource.ServiceFee]
//   m_Service = CityService.Police
//   m_BudgetAdjustable = true

// After prefab conversion, LateInitialize runs:
DynamicBuffer<CollectedCityServiceFeeData> fees = entityManager.GetBuffer<CollectedCityServiceFeeData>(entity);
// fees will contain entries for each configured PlayerResource

entityManager.SetComponentData(entity, new ServiceData
{
    m_Service = CityService.Police,
    m_BudgetAdjustable = true
});

If you want, I can: - Expand the example to show full ECS conversion flow, - Map the related component/data types (ServiceData, CollectedCityServiceFeeData, etc.) with their fields if you provide their definitions, - Suggest safe-guarding or editor UI helper code to validate m_CityResources.