Overview
Basics
The Variables system consists of three categories of components. Note that any script can set and get variable values through static methods SetVariable and GetVariable without any special implementation. The following components however need to implement IVariablesServiceComponent to be part of the variables system.
1) VariablesService
@NoSuchStudio.Localization.VariablesService acts as the central hub for the variables framework. There must be a single instance of this component in the scene. I recommend marking the GameObject DontDestroyOnLoad. If there are multiple instances of this script, the one that gets enabled last will act as the registered and active instance.
Other components that participate in the process register with this service instance and are able to make new variables, watch the current variables and change their values.
2) Variable Sources
Variable sources are components that provide variables to the system. They could store the variable values on disk, in the cloud or in memory. It really depends on the component how to store their variables. This asset comes with in-memory and persistant local storage sources. You can write your own sources too. For example you could store and retrieve variables from a Google sheet or a SQL database.
3) Consumers
Components that want to listen to variable change events. The asset comes with the VariablesListener component. This flexible component can be configured from Unity Editor to listen for changes to the selected variables and invoke a callback when any of those variables changes.
See Also
- Read the Getting Started page to start using No Such Studio: Variables asset.
- You can access the scripting API reference here.