Skip to content

Game.Prefabs.GarbagePowered

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Component for garbage facilities that require/consume power. Exposes editable parameters for how much "production" each unit produces and the facility's capacity, and maps those values into the ECS world by writing a GarbagePoweredData component to the entity during initialization. The MonoBehaviour is annotated to require GarbageFacility and PowerPlant components and is placed in the Buildings/CityServices component menu.


Fields

  • public float m_ProductionPerUnit
    Stores the production (output) amount produced per unit. Copied into the ECS GarbagePoweredData on Initialize. Editable in the prefab/inspector.

  • public int m_Capacity
    The capacity of the garbage-powered facility (integer). Copied into the ECS GarbagePoweredData on Initialize. Editable in the prefab/inspector.

Properties

  • This class does not declare any C# properties.

Constructors

  • public GarbagePowered()
    Default parameterless constructor (compiler-provided). The class uses Unity's component lifecycle and initialization via the overridden Initialize method.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the ECS component type that this MonoBehaviour requires on the entity. Implementation:
  • Adds ComponentType.ReadWrite<GarbagePoweredData>() to the provided set so the entity archetype includes the GarbagePoweredData component.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    No archetype-level components are added by this implementation (method body empty).

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Writes a GarbagePoweredData instance into the provided entity using the current MonoBehaviour field values:

  • Calls entityManager.SetComponentData(entity, new GarbagePoweredData { m_ProductionPerUnit = m_ProductionPerUnit, m_Capacity = m_Capacity });

Additional notes: - Class attributes: - [RequireComponent(typeof(GarbageFacility), typeof(PowerPlant))] — ensures the GameObject also has GarbageFacility and PowerPlant components. - [ComponentMenu("Buildings/CityServices/", new Type[] { typeof(BuildingPrefab), typeof(BuildingExtensionPrefab) })] — places the component in the specified component menu.

Usage Example

// Configure via inspector or at runtime:
var gp = gameObject.GetComponent<Game.Prefabs.GarbagePowered>();
gp.m_ProductionPerUnit = 2.5f;
gp.m_Capacity = 1200;

// If you need to manually initialize the ECS entity (normally handled by the prefab/system):
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity entity = /* obtain or create entity matching prefab */;
gp.Initialize(entityManager, entity);