Method RefreshString
RefreshString()
Forces the string to be regenerated, such as when the string formatting argument values have changed.
Declaration
public void RefreshString()
Examples
This example shows how to refresh the string when the value of a variable has changed.
public class RefreshStringExample : MonoBehaviour
{
// Set via inspector
public LocalizeStringEvent localizeStringEvent;
// Set via code
[HideInInspector]
public int someValue;
void Start()
{
// Assuming the localized string is in the format "The value is {someValue}"
localizeStringEvent.StringReference.Arguments = new object[] { this };
// Add a listener to the event
localizeStringEvent.OnUpdateString.AddListener(OnStringChanged);
}
void OnStringChanged(string s)
{
Debug.Log($"String changed to `{s}`");
}
public void SetValue(int value)
{
someValue = value;
// The localized string does not know the value has changed so we call RefreshString to force an update.
localizeStringEvent.RefreshString();
}
}