Class ObjectVariable
Inherited Members
Namespace: UnityEngine.Localization.SmartFormat.PersistentVariables
Assembly: Unity.Localization.dll
Syntax
[Serializable]
[DisplayName("Object Reference", null)]
public class ObjectVariable : Variable<Object>, IVariableValueChanged, IVariable, ISerializationCallbackReceiver
Remarks
This class is serializable. You can use it in the Inspector. Modifying its Value triggers the ValueChanged event, automatically updating any Smart Strings displaying the value.
Examples
The following example shows how to create a BoolVariable and use it in a LocalizedString.
public class BoolVariableSample : MonoBehaviour
{
// Assuming the Localizing String is set in the inspector and is in the format "The door is {door-state:choose(Open|Closed)}"
public LocalizedString localizedString;
BoolVariable m_Variable;
void Start()
{
m_Variable = new BoolVariable { Value = false };
localizedString.Add("door-state", m_Variable);
}
public void OpenDoor() => m_Variable.Value = true;
public void CloseDoor() => m_Variable.Value = false;
}
The following example shows how to create a SByteVariable and use it in a LocalizedString.
public class SByteVariableSample : MonoBehaviour
{
// Assuming the Localizing String is set in the inspector and is in the format "The value is {my-value}"
public LocalizedString localizedString;
SByteVariable m_Variable;
void Start()
{
m_Variable = new SByteVariable { Value = 1 };
localizedString.Add("my-value", m_Variable);
}
public void SetValue(sbyte value) => m_Variable.Value = value;
}
The following example shows how to create a DoubleVariable and use it in a LocalizedString.
public class DoubleVariableSample : MonoBehaviour
{
// Assuming the Localizing String is set in the inspector and is in the format "The road is {length}m long."
public LocalizedString localizedString;
DoubleVariable m_Variable;
public double Length
{
get => m_Variable.Value;
set => m_Variable.Value = value;
}
void Start()
{
m_Variable = new DoubleVariable { Value = 100 };
localizedString.Add("length", m_Variable);
}
}