Game.Prefabs.PolicyPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: abstract class
Base: PrefabBase
Summary:
Abstract base prefab for in-game policies. PolicyPrefab provides common data and prefab-component registration for policy entities used by the game (for example city-level policies that can be enabled/disabled). It exposes visibility and category metadata and ensures the runtime entity receives the PolicyData component. The class is marked with Unity's ComponentMenu attribute so derived prefabs appear under the "Policies/" menu inside the Unity editor.
Fields
-
public PolicyVisibility m_Visibility
A field indicating how/where the policy is visible in the UI. Uses the PolicyVisibility enum (project-specific). Modders can set this in derived prefabs to control UI presentation and filtering for the policy. -
public PolicyCategory m_Category
A field specifying the category of the policy (uses the PolicyCategory enum). Categories group policies in the UI (for example Residential, Commercial, Transport, etc.). Set this on the prefab to control grouping and filtering.
Properties
- This class does not declare any properties.
Constructors
public PolicyPrefab()
The default constructor (implicit). PolicyPrefab is abstract so it cannot be instantiated directly; derive from it to create concrete policy prefabs.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Overrides PrefabBase.GetPrefabComponents to collect the set of ECS components that should be added to entities created from this prefab. Implementation:- Calls base.GetPrefabComponents(components) to include components registered by the base class.
-
Adds PolicyData as a read/write component (ComponentType.ReadWrite
()) so the entity receives the runtime component that holds the policy's state/parameters. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Override of PrefabBase.LateInitialize. Current implementation forwards to base.LateInitialize(entityManager, entity) and does not add additional runtime initialization. Derived classes can override this method to perform extra setup (for example writing initial PolicyData values into the entity or adding more components).
Usage Example
using Unity.Entities;
using Game.Prefabs;
[ComponentMenu("Policies/MyCustomPolicy", new Type[] { })]
public class MyCustomPolicyPrefab : PolicyPrefab
{
public override void GetPrefabComponents(HashSet<ComponentType> components)
{
base.GetPrefabComponents(components);
// add other components your policy entities need
components.Add(ComponentType.ReadWrite<MyCustomPolicyData>());
}
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
// initialize PolicyData or other components for the concrete policy
if (entityManager.HasComponent<PolicyData>(entity))
{
var data = entityManager.GetComponentData<PolicyData>(entity);
// set default values on data as needed, then write back
// data.someField = defaultValue;
entityManager.SetComponentData(entity, data);
}
}
}
Notes and tips: - PolicyData is the runtime ECS component representing the policy state; ensure you know its fields before modifying them in LateInitialize. - Because PolicyPrefab is abstract, create concrete subclasses to represent individual policies and set m_Visibility and m_Category on those subclasses (or via the Unity inspector if the prefab is serialized). - The ComponentMenu attribute controls where the prefab appears in Unity's "Create" menu; keep the path consistent with other policy prefabs to maintain editor organization.