Class ByteVariable
An IVariable implementation that holds a single byte value.
Inherited Members
Namespace: UnityEngine .Localization.SmartFormat .PersistentVariables
Assembly: Unity.Localization.dll
Syntax
[Serializable]
[DisplayName("Byte", null)]
public class ByteVariable : Variable<byte>, IVariableValueChanged, IVariable, ISerializationCallbackReceiver
Remarks
This class is serializable. You can use it in the Inspector.
Modifying its Value triggers the Value
Examples
The following example shows how to create a Bool
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 SByte
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 Double
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);
}
}