Skip to content

Game.Prefabs.ResourceStatistic

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs

Type:
class

Base:
ParametricStatistic

Summary:
ResourceStatistic is a ParametricStatistic component that exposes a set of resource parameters (from ResourcePrefab entries) for use by the game's statistics systems. It iterates the configured ResourcePrefab array (m_Resources) and yields StatisticParameterData values containing the resource index and display color. Parameter names are resolved to the Resource enum name via EconomyUtils.


Fields

  • public ResourcePrefab[] m_Resources
    Array of ResourcePrefab entries that define which resources this statistic should expose. Each ResourcePrefab provides a reference to a resource and a color; ResourceStatistic converts those into StatisticParameterData (resource index + color) for the statistics system. If this array is null, GetParameters() yields nothing.

Properties

  • None declared (inherits any properties from ParametricStatistic)

Constructors

  • public ResourceStatistic()
    Default public constructor (no special initialization in-source).

Methods

  • public override IEnumerable<StatisticParameterData> GetParameters()
    Returns an enumerable sequence of StatisticParameterData items produced from m_Resources. For each non-null ResourcePrefab in m_Resources it:
  • Resolves the Resource enum from the prefab via EconomyUtils.GetResource(resourcePrefab.m_Resource)
  • Converts the Resource enum to a resource index via EconomyUtils.GetResourceIndex(...)
  • Yields a new StatisticParameterData(resourceIndex, resourcePrefab.m_Color)

This method performs a null check on m_Resources and uses yield return, so the sequence is lazily evaluated.

  • public override string GetParameterName(int parameter)
    Given a resource index (parameter), this resolves the corresponding Resource enum via EconomyUtils.GetResource(parameter) and returns the enum name as a string via Enum.GetName. Use this to obtain a human-readable name for a parameter produced by GetParameters().

Usage Example

using System.Collections.Generic;
using UnityEngine;
using Game.Prefabs;

// Example: iterate the parameters provided by a ResourceStatistic component and build labels.
public void ShowResourceStatistics(ResourceStatistic stat)
{
    if (stat == null) return;

    foreach (StatisticParameterData param in stat.GetParameters())
    {
        // Assuming StatisticParameterData exposes 'parameter' (int) and 'color' (Color)
        int resourceIndex = param.parameter;
        Color displayColor = param.color;

        string name = stat.GetParameterName(resourceIndex);
        Debug.Log($"Resource: {name} (index {resourceIndex}), color: {displayColor}");
    }
}

Notes and tips for modders: - Populate m_Resources on your statistic prefab with ResourcePrefab entries to control which resources are shown and the color used for each. - The mapping uses EconomyUtils to go between ResourcePrefab resource references, Resource enum values, and resource indices — follow the same utility functions if you need to resolve resource data elsewhere. - GetParameters uses lazy enumeration (yield return), so consuming code should enumerate it fully when needed (e.g., ToList()) if you need snapshot semantics.