Game.Prefabs.CityEffects
Assembly:
Game
Namespace:
Game.Prefabs
Type:
class
Base:
ComponentBase, IServiceUpgrade
Summary:
Component used on building prefabs (BuildingPrefab / BuildingExtensionPrefab via the ComponentMenu attribute) to declare city-wide effects provided by that building. CityEffects exposes an array of CityEffectInfo entries (m_Effects) which are converted into CityModifierData entries and written into the entity's DynamicBuffer during prefab initialization. The component also declares which ECS components (CityModifierData and, conditionally, CityEffectProvider) the prefab or upgrade archetype should include so runtime systems can consume these modifiers.
Fields
public CityEffectInfo[] m_Effects
Array of effect definitions assigned on the prefab. Each CityEffectInfo contains fields such as m_Type, m_Mode and m_Delta. During Initialize, each entry in this array is converted into a CityModifierData (using a Bounds1 constructed with 0..m_Delta) and added to the entity's DynamicBuffer. If this array is null, no modifier entries are added.
Properties
- None declared on this class.
Constructors
public CityEffects()
Implicit/default constructor. No custom construction logic is defined in the class; initialization of behavior happens in the Initialize method when the prefab is materialized into an entity.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds ComponentType.ReadWrite() to the provided components set. This ensures prefab entities have a DynamicBuffer available to store the modifiers declared by m_Effects. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
If the prefab does not already include a ServiceUpgrade component, this method adds ComponentType.ReadWrite() to the archetype components. The CityEffectProvider component is used at runtime to identify entities that provide the declared city effects. -
public void GetUpgradeComponents(HashSet<ComponentType> components)
When the prefab is used as a service upgrade (IServiceUpgrade), this method declares that the upgrade archetype should include ComponentType.ReadWrite() so the upgrade also registers as an effect provider. -
public override void Initialize(EntityManager entityManager, Entity entity)
If m_Effects is not null, this method obtains the DynamicBufferfrom the given entity and appends a CityModifierData entry for each CityEffectInfo in m_Effects. Each entry is constructed from the effect's m_Type and m_Mode and a Bounds1 created as new Bounds1(0f, cityEffectInfo.m_Delta). This populates the entity so runtime systems can read and apply the city modifiers.
Notes / behavior details:
- The class relies on Unity.Entities (EntityManager, Entity, DynamicBuffer
Usage Example
// Example: a prefab that uses CityEffects will have its m_Effects configured in the prefab asset.
// At initialization (when the prefab is converted to an entity), the CityEffects.Initialize method
// will add CityModifierData entries into the entity's buffer for the declared effects.
[ComponentMenu("Buildings/", new Type[] { typeof(BuildingPrefab), typeof(BuildingExtensionPrefab) })]
public class MyServiceBuilding : CityEffects
{
// Configure m_Effects in the prefab inspector (array of CityEffectInfo).
// No extra code required: CityEffects.Initialize will add the corresponding CityModifierData.
}
Note: If m_Effects is left null on the prefab, no CityModifierData entries are added. Ensure other systems that expect CityEffectProvider/CityModifierData are present via the prefab or upgrade archetype declarations.