Hi thepunkoff,
There actually is a way to do exactly that!
Global Variables are stored inside an instance of
BaseGlobalVariables. You can have multiple of those
to keep track of different sets of your variables, but most of the time you only need one. This one is automatically created for you and accessible via
- Code: Select all
ArticyDatabase.DefaultGlobalVariables
or if you want C# access to your global variables; via the generated class(Both ways point to the exact same instance, just with different types)
- Code: Select all
ArticyGlobalVariables.Default
Either way you can access now the
Notification Manager. Here you can register a method to be called everytime a global variables is modified.
- Code: Select all
public class MyNotificationScript : MonoBehaviour
{
void Start()
{
// we get the default variable storage from our database and add a listener to the notification manager
// to call our supplied method every time any Variable inside the namespace "GameState" is changed.
ArticyDatabase.DefaultGlobalVariables.Notifications.AddListener("GameState.*", MyGameStateVariablesChanged);
}
// here we handle every variable change inside the "GameState" namespace
void MyGameStateVariablesChanged(string aVariableName, object aValue)
{
// for example:
// When our exit variable was set to true, we quit the game.
if(aVariableName == "GameState.exit" && ((bool)aValue) == true)
Application.Quit();
// in this example we play a beep when the variable changes
// its worth noting that we won't hear a beep now every frame once the variable has been set to true. Because our listener method will only
// be called once, when our variable changes.
if(aVariableName == "GameState.beep" && ((bool) aValue) == true)
EditorApplication.Beep();
}
}
We do this for the inventory management in our Maniac Manfred Demo project(A small Point&Click Adventure), where the possession of an item is marked via global variable, everytime it changed the item gets added or removed from the players inventory. This turned out great for debugging, as even changing the GV via the inspector view, triggeres those events.
Hope that helped!
Best regards
Nico