Class PersistentVariablesSource
Can be used to provide global or local values that do not need to be passed in as arguments when formatting a string. The smart string should take the format {groupName.variableName}. e.g {global.player-score}. Note: The group name and variable names must not contain any spaces.
Namespace: UnityEngine.Localization.SmartFormat.Extensions
Syntax
public class PersistentVariablesSource : object, ISource, IDictionary<string, VariablesGroupAsset>, ISerializationCallbackReceiver
Constructors
PersistentVariablesSource(SmartFormatter)
Creates a new instance and adds the "." operator to the parser.
Declaration
public PersistentVariablesSource(SmartFormatter formatter)
Parameters
Type | Name | Description |
---|---|---|
SmartFormatter | formatter |
Properties
Count
The number of VariablesGroupAsset that are used for global variables.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
IsReadOnly
Implmented as part of IDictionary but not used. Will always return false
.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsUpdating
Has BeginUpdating() been called? This can be used when updating the value of multiple IVariable in order to do a single update after the updates instead of 1 per change.
Declaration
public static bool IsUpdating { get; }
Property Value
Type | Description |
---|---|
Boolean |
Item[String]
Returns the global variable group that matches name
.
Declaration
public VariablesGroupAsset this[string name] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the group to return. |
Property Value
Type | Description |
---|---|
VariablesGroupAsset |
Keys
Returns the global variable group names.
Declaration
public ICollection<string> Keys { get; }
Property Value
Type | Description |
---|---|
ICollection<String> |
Values
Returns the global variable groups for this source.
Declaration
public ICollection<VariablesGroupAsset> Values { get; }
Property Value
Type | Description |
---|---|
ICollection<VariablesGroupAsset> |
Methods
Add(KeyValuePair<String, VariablesGroupAsset>)
Add a global variable group to the source.
Declaration
public void Add(KeyValuePair<string, VariablesGroupAsset> item)
Parameters
Type | Name | Description |
---|---|---|
KeyValuePair<String, VariablesGroupAsset> | item |
Add(String, VariablesGroupAsset)
Add a global variable group to the source.
Declaration
public void Add(string name, VariablesGroupAsset group)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the group to add. |
VariablesGroupAsset | group | The group to add. |
BeginUpdating()
Indicates that multiple IVariable will be changed and LocalizedString should wait for EndUpdate before updating. See EndUpdating() and EndUpdate. Note: BeginUpdating() and EndUpdating() can be nested, EndUpdate will only be called after the last EndUpdate.
Declaration
public static void BeginUpdating()
Clear()
Removes all global variables.
Declaration
public void Clear()
Contains(KeyValuePair<String, VariablesGroupAsset>)
Returns true
if a global variable group is found with the same name.
Declaration
public bool Contains(KeyValuePair<string, VariablesGroupAsset> item)
Parameters
Type | Name | Description |
---|---|---|
KeyValuePair<String, VariablesGroupAsset> | item |
Returns
Type | Description |
---|---|
Boolean |
|
ContainsKey(String)
Returns true
if a global variable group is found with the same name.
Declaration
public bool ContainsKey(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the global variable group to check for. |
Returns
Type | Description |
---|---|
Boolean |
|
CopyTo(KeyValuePair<String, VariablesGroupAsset>[], Int32)
Copy all global variable groups into the provided array starting at arrayIndex
.
Declaration
public void CopyTo(KeyValuePair<string, VariablesGroupAsset>[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
KeyValuePair<String, VariablesGroupAsset>[] | array | The array to copy the global variables into. |
Int32 | arrayIndex | The index to start copying into. |
EndUpdating()
Indicates that updates to IVariable have finished and sends the EndUpdate event. Note: BeginUpdating() and EndUpdating() can be nested, EndUpdate will only be called after the last EndUpdate.
Declaration
public static void EndUpdating()
GetEnumerator()
Returns an enumerator for all the global variables in the source.
Declaration
public IEnumerator GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator |
Remove(KeyValuePair<String, VariablesGroupAsset>)
Removes the group with the matching name.
Declaration
public bool Remove(KeyValuePair<string, VariablesGroupAsset> item)
Parameters
Type | Name | Description |
---|---|---|
KeyValuePair<String, VariablesGroupAsset> | item |
Returns
Type | Description |
---|---|
Boolean |
|
Remove(String)
Removes the group with the matching name.
Declaration
public bool Remove(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the group to remove. |
Returns
Type | Description |
---|---|
Boolean |
|
TryEvaluateSelector(ISelectorInfo)
Evaluates the ISelectorInfo based on the CurrentValue. If this extension cannot evaluate the Selector, returns False. Otherwise, sets the Result and returns true.
Declaration
public bool TryEvaluateSelector(ISelectorInfo selectorInfo)
Parameters
Type | Name | Description |
---|---|---|
ISelectorInfo | selectorInfo |
Returns
Type | Description |
---|---|
Boolean |
Implements
TryGetValue(String, out VariablesGroupAsset)
Returns true
if a global variable group could be found with a matching name, or false
if one could not.
Declaration
public bool TryGetValue(string name, out VariablesGroupAsset value)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the global variable group to find. |
VariablesGroupAsset | value | The found global variable group or |
Returns
Type | Description |
---|---|
Boolean |
|
UpdateScope()
Can be used to create a BeginUpdating() and EndUpdating() scope.
Declaration
public static IDisposable UpdateScope()
Returns
Type | Description |
---|---|
IDisposable |
Events
EndUpdate
Called after the final EndUpdating() has been called. This can be used when you wish to respond to value change events but wish to do a single update at the end instead of 1 per change. For example, if you wanted to change the value of multiple global variables that a smart string was using then changing each value would result in a new string being generated, by using begin and end the string generation can be deferred until the final change so that only 1 update is performed.
Declaration
public static event Action EndUpdate
Event Type
Type | Description |
---|---|
Action |