ScopedVariable<T>

class ScopedVariable<T> : ScopedVariableBase

A ScopedVariable is a type that allows to create a field that either contains a local value or a GlobalVariable that represents a value of the same type.

  [SerializeField]
private ScopedVariable<int> myNumber;

Legacy note: When using an older version than Unity 2020.1, it is required to create a subtype of ScopedVariableBase<T, GVT> in order to be able to serialize the ScopedVariable object. For compatibility reasons, a set of predefined ScopedVariable types (ScopedBool, ScopedInt, ...) is still included in the package, but they are marked as obsolete when opened in Unity 2020.1 or newer.

T: The type of the value being represented.

Properties

value : T

The value represented by this ScopedVariable. If the ScopedVariable is set to reference a GlobalVariable, this property will get or set that GlobalVariable's value. Gets or sets the local value instead if the ScopedVariable is set to local value mode.

onChangeValue : SodaEvent<T>

This event is invoked when the value changes, be it the local value, the value of the referenced GlobalVariable or when switching between local value and GlobalVariable.

Methods

ScopedVariable()

(Constructor)

ScopedVariable(T value)

(Constructor)

Creates a new ScopedVariable with a default local value. Sets the ScopedVariable to local value mode.

void AssignGlobalVariable(GlovalVariableBase<T> globalVariable)

Assign a GlobalVariable to be referenced by this ScopedVariable.

void AssignLocalValue(T value)

Assign a local value to this ScopedVariable. Any assigned GlobalVariable will be ignored, and the value property will represent this local value.