Method RefreshString
RefreshString()
Provides a way to force a refresh of the string when using String
Declaration
public bool RefreshString()
Returns
Type | Description |
---|---|
bool | Returns true if a new refresh could be requested or false if it could not, such as when Current |
Remarks
This will only force the refresh if there is currently no active Current
Examples
This example shows how the string can be refreshed, such as when showing dynamic values like the current time.
/// <summary>
/// This example expects a Smart String with a named placeholder of `TimeNow`, such as "The time now is {TimeNow}".
/// </summary>
public class LocalizedStringSmart : MonoBehaviour
{
public LocalizedString myString;
string localizedText;
public float TimeNow => Time.time;
/// <summary>
/// Register a ChangeHandler. This is called whenever we need to update our string.
/// </summary>
void OnEnable()
{
myString.Arguments = new[] { this };
myString.StringChanged += UpdateString;
}
void OnDisable()
{
myString.StringChanged -= UpdateString;
}
void UpdateString(string s)
{
localizedText = s;
}
void OnGUI()
{
// This calls UpdateString immediately (if the table is loaded) or when the table is available.
myString.RefreshString();
GUILayout.Label(localizedText);
}
}