Skip to content

Game.Prefabs.Climate.OverrideablePropertiesComponent

Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Climate

Type: abstract class

Base: ComponentBase

Summary:
An abstract base component used by climate-related prefabs to hold and manage a set of Unity VolumeParameter instances that can be overridden and interpolated. It discovers VolumeParameter fields via reflection (including nested object parameters), exposes a read-only list of parameters, provides interpolation mode/time settings, and utilities for enabling, binding and copying/interpolating override state between instances.


Fields

  • public InterpolationMode m_InterpolationMode
    Controls how interpolation between states should be driven. Defined by the nested enum InterpolationMode with values: RealTime, Cloudiness, Precipitation, RenderingTime, Aurora.

  • public float m_InterpolationTime = 5f
    Default time used for interpolation in some systems; stored on the component and copied when performing a three-way Override(previous, to, factor).

Properties

  • public bool hasTimeBasedInterpolation { get; }
    Returns true if interpolation mode is time-based. Implementation returns true for RealTime and RenderingTime modes; false otherwise. Use this to determine whether time should drive interpolation.

  • public ReadOnlyCollection<VolumeParameter> parameters { get; private set; }
    Read-only collection of VolumeParameter instances discovered on the component. Populated by CollectVolumeParameters() or Bind(). The collection preserves discovery ordering (fields ordered by MetadataToken).

Constructors

  • public OverrideablePropertiesComponent()
    No explicit constructor in code — uses default constructor. Subclasses typically rely on OnEnable/Bind/CollectVolumeParameters to initialize the parameters collection.

Methods

  • protected abstract void OnBindVolumeProperties(Volume volume)
    Abstract method subclasses must implement to bind component fields to a given UnityEngine.Rendering.Volume instance. Called by Bind(Volume).

  • protected override void OnEnable()
    Collects volume parameters (CollectVolumeParameters) and calls OnEnable() on each discovered VolumeParameter. Logs a warning when a discovered parameter is null. Use this to ensure parameters are initialized when the component is enabled.

  • public void Bind(Volume volume)
    Calls subclass OnBindVolumeProperties(volume) and then re-collects parameters. Intended to attach this component's VolumeParameter fields to an actual Volume.

  • public void CollectVolumeParameters()
    Rebuilds the parameters collection by discovering all fields that subclass VolumeParameter. Uses reflection and the private FindParameters recursive helper to locate parameters including those nested inside object fields.

  • public FieldInfo[] GetFieldsInfo()
    Returns FieldInfo[] for this instance's fields whose FieldType is a subclass of VolumeParameter. Fields are ordered by MetadataToken. Useful for editor tooling or debugging to inspect which VolumeParameters are present.

  • private static void FindParameters(object o, List<VolumeParameter> parameters, Func<FieldInfo, bool> filter = null)
    Reflection helper that recursively inspects the object's instance fields (public and non-public), ordered by MetadataToken. If a field's type is subclass of VolumeParameter it is added to the list (subject to optional filter). If the field is a reference-type non-array class, it recurses into that field's value to find nested parameters.

  • private void SetOverridesTo(IEnumerable<VolumeParameter> enumerable, bool state)
    Sets overrideState on each provided VolumeParameter to the given state. If an item is an object parameter (VolumeParameter.IsObjectParameter), it uses reflection to get the private "parameters" property on that object-type parameter and recursively sets overrides for contained parameters as well.

  • public void SetAllOverridesTo(bool state)
    Convenience that calls SetOverridesTo(parameters, state) to set overrideState for all discovered parameters.

  • public virtual void Override(OverrideablePropertiesComponent state, float interpFactor = 1f)
    Copies and interpolates parameter values from this instance (source) into the supplied 'state' instance when the source parameter's overrideState is true. For each parameter index, it sets state.parameters[i].overrideState and calls Interp on the VolumeParameter to blend values using interpFactor.

  • public virtual void Override(OverrideablePropertiesComponent previous, OverrideablePropertiesComponent to, float interpFactor = 1f)
    Three-way override used for interpolating between a previous and a target ("to") state into this instance. Copies m_InterpolationMode and m_InterpolationTime from the 'to' instance. For each parameter where the target has overrideState true, sets the current parameter's overrideState and interpolates between previous and target parameter values using interpFactor.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Overridden but empty in this class — reserved for registering required ECS component types for prefabs. Subclasses may override if needed.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Overridden but empty — reserved for registering required ECS archetype components. Subclasses may override if needed.

Usage Example

// Example subclass that binds specific VolumeParameter fields to a Volume.
public class MyClimateOverrideComponent : OverrideablePropertiesComponent
{
    // Example VolumeParameter fields (these would be real VolumeParameter-derived types).
    // public FloatParameter m_SomeFloat;
    // public ColorParameter m_SomeColor;

    protected override void OnBindVolumeProperties(Volume volume)
    {
        // Example pseudo-code: bind the VolumeParameter fields to components on the Volume
        // m_SomeFloat.Bind(volume);
        // m_SomeColor.Bind(volume);

        // After binding, re-collect parameters to ensure 'parameters' list is up to date.
        // (Bind() already calls CollectVolumeParameters, so this is optional here.)
    }

    protected override void OnEnable()
    {
        base.OnEnable();
        // Optionally set defaults, or force all overrides on/off:
        SetAllOverridesTo(false);
    }
}

// Using the component:
var myComponent = /* obtain component from prefab or instance */;
var targetVolume = /* UnityEngine.Rendering.Volume instance */;
myComponent.Bind(targetVolume);

// Copy overrides from one component to another and interpolate 50%
var a = /* previous */;
var b = /* target */;
var result = /* a new instance or existing one */;
result.Override(a, b, 0.5f);

Notes and implementation details: - Reflection is used extensively; field discovery preserves declaration order via MetadataToken ordering. - FindParameters recurses into non-array class fields to support nested parameter objects. - For object-type VolumeParameters (compound parameters) the code reflects into a non-public "parameters" property to manipulate contained parameters. - OnEnable will call OnEnable() on each discovered VolumeParameter and will log a warning if any parameter is null — ensure fields are initialized before enabling the component.