Skip to content

Game.Prefabs.ParametricStatistic

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: abstract class

Base: StatisticsPrefab

Summary:
ParametricStatistic is an abstract prefab base class used by the game's statistics system to define statistics that expose a variable/parameter list. It ensures required ECS components are declared for prefabs and archetypes and populates an entity's DynamicBuffer at initialization using the parameters provided by concrete subclasses. Subclasses must implement how parameters are supplied and how parameter names are resolved.


Fields

  • This class defines no private or public fields in its source.

Properties

  • This class declares no properties.

Constructors

  • public ParametricStatistic()
    The class does not declare an explicit constructor; it uses the default parameterless constructor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds components required for prefab instances. This override calls the base implementation and then ensures StatisticParameterData is added as a read/write component so entity prefabs will include the parameter data buffer.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds components required for entity archetypes. This override calls the base implementation and then ensures StatisticParameter is added as a read/write component to archetypes, so entities of this type will have the parameter metadata component.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Called after the entity has been created. It calls the base LateInitialize, obtains the DynamicBuffer for the entity, and fills that buffer with each StatisticParameterData element returned by GetParameters(). This is where subclass-provided parameters are copied into the entity's buffer.

  • public abstract IEnumerable<StatisticParameterData> GetParameters()
    Abstract method that concrete subclasses must implement to provide the sequence of StatisticParameterData instances that define the parameters for this statistic. The returned enumerable is iterated in LateInitialize and each element is added to the entity's parameter buffer.

  • public abstract string GetParameterName(int parameter)
    Abstract method that concrete subclasses must implement to translate a parameter index (or id) into a displayable name. Used by the statistics UI or systems that need human-readable parameter names.

Usage Example

// Example concrete implementation of ParametricStatistic
[ComponentMenu("Statistics/MyParametricStatistic", new Type[] { })]
public class MyParametricStatistic : ParametricStatistic
{
    // Provide the parameters that should be stored in the entity buffer
    public override IEnumerable<StatisticParameterData> GetParameters()
    {
        yield return new StatisticParameterData { /* fill fields for parameter 0 */ };
        yield return new StatisticParameterData { /* fill fields for parameter 1 */ };
        // Add as many parameters as needed
    }

    // Return a human-readable name for a parameter by index
    public override string GetParameterName(int parameter)
    {
        switch (parameter)
        {
            case 0: return "Population";
            case 1: return "Happiness";
            default: return $"Parameter {parameter}";
        }
    }
}

Notes and tips: - Ensure that StatisticParameterData and StatisticParameter types are available in your mod context; these are ECS components used by the statistics system. - LateInitialize will copy the data returned from GetParameters into the entity buffer, so avoid expensive operations in that method — prepare parameter data efficiently (e.g., using static/readonly data when possible). - Because this is an abstract prefab class, register concrete subclasses as prefabs in whatever prefab registration system your mod uses so they are processed and converted to entities at runtime.