Skip to content

Game.ServiceCoverage

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
ServiceCoverage is a prefab ComponentBase used to provide service coverage data for building prefabs. It exposes configurable public floats for range, capacity and magnitude and, on initialization, creates/sets a CoverageData component on the entity and infers the coverage service type (CoverageService) from the presence of other data components on the prefab (e.g., HospitalData → Healthcare, FireStationData → FireRescue, PoliceStationData → Police, ParkData → Park, PostFacilityData/MailBoxData → PostService, SchoolData → Education, EmergencyShelterData → EmergencyShelter, WelfareOfficeData → Welfare). If no known service component is found, it writes an error to the base logger. The class also registers the required ECS components for prefab and archetype creation.


Fields

  • public float m_Range = 1000f
    {{ This defines the effective range (in game units) of the service coverage provided by the prefab. Default value: 1000f. This value is copied into the CoverageData.m_Range when Initialize runs. }}

  • public float m_Capacity = 3000f
    {{ The capacity value used for the coverage calculations (how many people/units the service can handle). Default value: 3000f. This value is copied into CoverageData.m_Capacity in Initialize. }}

  • public float m_Magnitude = 1f
    {{ A magnitude multiplier (strength) of the coverage effect. Default value: 1f. Copied into CoverageData.m_Magnitude in Initialize. }}

Properties

  • None
    {{ This class does not expose any C# properties. Configuration is done via the public fields above, and runtime behavior is applied by the Initialize override which sets ECS component data. }}

Constructors

  • public ServiceCoverage()
    {{ No explicit constructor is defined in the source — the default parameterless constructor is used. Initialization of the component's fields relies on their declared defaults or whatever values are set in the prefab (inspector or code). }}

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    {{ Adds the ECS component types required on the prefab instance for this component to work. Specifically, it adds a read/write CoverageData component type so that CoverageData will be present on created entities. Use this to ensure the prefab has the CoverageData component in the prefab entity. }}

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    {{ Adds additional ECS component types to the entity archetype that the prefab will use. This method adds read/write CoverageServiceType and CoverageElement component types to the archetype so entities created from the prefab include those components. }}

  • public override void Initialize(EntityManager entityManager, Entity entity)
    {{ Called when the prefab is instantiated into an ECS entity. This method:

  • Creates a CoverageData struct populated from this component's m_Range, m_Capacity and m_Magnitude.
  • Detects the specific coverage service type by checking for presence of known data components on the prefab/entity manager (HospitalData, FireStationData, PoliceStationData, ParkData, PostFacilityData, MailBoxData, SchoolData, EmergencyShelterData, WelfareOfficeData) and sets componentData.m_Service to the appropriate CoverageService enum.
  • If no known service type is detected, logs an error via baseLog.ErrorFormat including the prefab name.
  • Writes the CoverageData to the entity via entityManager.SetComponentData. }}

Usage Example

// Example: add/modify ServiceCoverage on a prefab in code (typical usage done in editor/prefab setup)
var myPrefab = /* obtain prefab GameObject or PrefabBase reference */;
var svc = myPrefab.AddComponent<Game.Prefabs.ServiceCoverage>();
svc.m_Range = 1500f;
svc.m_Capacity = 4000f;
svc.m_Magnitude = 1.25f;

// When the prefab is converted to an ECS entity, ServiceCoverage.Initialize will be called:
// it will set a CoverageData component on the entity and detect the CoverageService
// based on other components present on the prefab (e.g., HospitalData => Healthcare).