Method RefreshString
RefreshString()
Provides a way to force a refresh of the string when using StringChanged.
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 CurrentLoadingOperationHandle is still loading. |
Remarks
This will only force the refresh if there is currently no active CurrentLoadingOperationHandle, if one is still being executed then it will be ignored and false will be returned. If a string is not static and will change during game play, such as when using format arguments, then this can be used to force the string to update itself.
You may wish to call this if the values inside of the Arguments list have changed or you wish to force all StringChanged subscribers to update.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);
}
}