Game.Prefabs.PoliceConfigurationPrefab
Assembly: Assembly-CSharp (game assembly)
Namespace: Game.Prefabs
Type: class
Base: PrefabBase
Summary:
Prefab that exposes police-related configuration and references to other prefabs (police service prefab and notification icon prefabs). It is decorated with a ComponentMenu attribute ("Settings/") so it is intended to be configured in Unity/inspector and later converted to an ECS component (PoliceConfigurationData) during prefab initialization. The prefab holds tuning values for crime accumulation, effects, and how police coverage/population affect crime.
Fields
-
public PrefabBase m_PoliceServicePrefab
Reference to the police service prefab (service building/entity) that police code will spawn or use. -
public NotificationIconPrefab m_TrafficAccidentNotificationPrefab
Reference to a notification icon prefab for traffic accident notifications. -
public NotificationIconPrefab m_CrimeSceneNotificationPrefab
Reference to a notification icon prefab for crime scene notifications. -
public float m_MaxCrimeAccumulation = 100000f
Maximum stored crime accumulation value. Used to cap the internal crime accumulation metric. -
public float m_CrimeAccumulationTolerance = 1000f
Tolerance threshold applied when calculating crime accumulation changes. -
public int m_HomeCrimeEffect = 15
Crime effect value for home/residential locations. -
public int m_WorkplaceCrimeEffect = 5
Crime effect value for workplaces. -
public float m_WelfareCrimeRecurrenceFactor = 0.4f
Factor used to scale recurrence of crime related to welfare effects. -
public float m_CrimePoliceCoverageFactor = 2f
(Formerly serialized name: m_CrimeIncreaseMultiplier) Factor multiplying the crime increase formula that includes police coverage. Tooltip: "Crime increase factor of police coverage, multiply with the result of formula[ crimeIncrease * (10-coverage) / 10 ], the bigger the crime increase more(less police affect), the smaller the crime increase less(more police affect)". -
public float m_CrimePopulationReduction = 2000f
Used to reduce crime probability according to population. Tooltip: "Reduce the crime possibility according to the population, the possibility random will be calculated by population / CrimePopulationReduction * 100, and not less than 100".
Properties
public override bool ignoreUnlockDependencies => true
Indicates this prefab ignores unlock dependencies (override). Always returns true in this class.
Constructors
public PoliceConfigurationPrefab()
Default constructor. Field default values are declared inline in the class (see fields above).
Methods
public override void GetDependencies(System.Collections.Generic.List<PrefabBase> prefabs)
Adds referenced prefabs to the provided dependency list so the prefab system knows to load/create them. This implementation calls base.GetDependencies(prefabs) and then adds:- m_PoliceServicePrefab
- m_TrafficAccidentNotificationPrefab
-
m_CrimeSceneNotificationPrefab
-
public override void GetPrefabComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
Registers the runtime ECS component(s) that this prefab requires. This implementation adds ComponentType.ReadWrite() so that the resulting entity will include that component. -
public override void LateInitialize(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity entity)
Called during prefab initialization. Creates and populates a PoliceConfigurationData struct from the prefab's fields, resolving referenced PrefabBase/NotificationIconPrefab instances into Entities via PrefabSystem.GetEntity, copies all tuning values into the struct, and writes it to the given entity with entityManager.SetComponentData(entity, componentData).
Notes:
- LateInitialize uses PrefabSystem orCreateSystemManaged = entityManager.World.GetOrCreateSystemManaged
Usage Example
// Example: reading the PoliceConfigurationData that LateInitialize writes to the prefab entity.
// Usually this entity is created during prefab initialization; here is how a system can read it.
public partial class PoliceSystem : SystemBase
{
private Entity policeConfigEntity;
private PoliceConfigurationData policeConfig;
protected override void OnCreate()
{
// Obtain the prefab entity from the PrefabSystem (example: assuming you have the PrefabBase instance)
var prefabSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<PrefabSystem>();
policeConfigEntity = prefabSystem.GetEntity(myPoliceConfigurationPrefab); // myPoliceConfigurationPrefab is the PoliceConfigurationPrefab asset
// Read the component data populated in LateInitialize
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
if (em.HasComponent<PoliceConfigurationData>(policeConfigEntity))
{
policeConfig = em.GetComponentData<PoliceConfigurationData>(policeConfigEntity);
// Use policeConfig.m_MaxCrimeAccumulation, policeConfig.m_PoliceServicePrefab (Entity), etc.
}
}
}
Additional notes: - Configure values in the Unity inspector on the PoliceConfigurationPrefab asset to tune police/crime behavior without changing code. - The PrefabSystem ensures the prefab references are converted to Entities and the PoliceConfigurationData component is present on the prefab's entity at runtime.