Skip to content

Game.Prefabs.ResourceConsumption

Assembly:
Assembly-CSharp.dll (typical Unity/City Skylines 2 game assembly; verify in your project if different)

Namespace:
Game.Prefabs

Type:
public class ResourceConsumption

Base:
ComponentBase

Summary:
ResourceConsumption is a prefab component used to declare resources consumed by a building prefab or building extension prefab. It exposes an array of ResourceConsumptionItem that describes one or more resource consumption entries. The class is annotated with a ComponentMenu attribute so it appears under the "Buildings/" menu for prefabs (associated with BuildingPrefab and BuildingExtensionPrefab). The two override methods for collecting ECS component types are present but currently have empty implementations.


Fields

  • public ResourceConsumptionItem[] m_Consumptions
    Holds the list/array of ResourceConsumptionItem entries for this prefab. Each entry represents a specific resource the building consumes and associated parameters (type definition for ResourceConsumptionItem is external to this file). This field is public and typically serialized by Unity so it can be edited on the prefab inspector.

Properties

  • This class does not declare any C# properties.

Constructors

  • public ResourceConsumption()
    No explicit constructors are declared in the source; the default parameterless constructor is used. Initialization of the m_Consumptions array is expected to be done via the Unity inspector or by code after instantiation.

Methods

  • public override void GetPrefabComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
    Override intended to add ComponentType entries required by this prefab to the provided hash set (used when building the prefab's entity representation). The method is empty in the current implementation, so no additional ECS component types are added by this class.

  • public override void GetArchetypeComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
    Override intended to add ComponentType entries required for the archetype (entity archetype) for this prefab. Also empty in the current implementation.

Note: Both methods accept a HashSet from Unity.Entities — if you are creating an ECS-backed prefab representation, you would typically add the appropriate ComponentType instances inside these methods (for example, ComponentType.ReadWrite).

Usage Example

// Example: setting up consumption data (can be done in code or via inspector)
public class ExampleSetup
{
    public void Configure(ResourceConsumption rc)
    {
        // Create and assign consumption entries in code
        rc.m_Consumptions = new ResourceConsumptionItem[]
        {
            new ResourceConsumptionItem
            {
                // fill fields according to ResourceConsumptionItem definition,
                // such as resource type, amount, interval, etc.
            }
        };
    }
}

Additional notes: - The ComponentMenu attribute places this component under "Buildings/" in the prefab component menu and associates it with BuildingPrefab and BuildingExtensionPrefab types so it can be added to those prefabs. - To integrate with Unity ECS for runtime behavior, implement GetPrefabComponents / GetArchetypeComponents to declare the ECS component types that the prefab's entities require.