Checking variables in GameController from a gameobject?
I am creating an email simulation and each email is an object called an EmailNode. Each email has a 4 different kinds of dependencies that need to be checked in order to be sent. A given email might have multiple dependencies of each type that it needs to check. One kind is stored in a dictionary of the form and I check if emailNode.selected == bool. This one is pretty strait forward. The ones giving me trouble are the ones that need to check the status of certain bools and ints stored in the gameController. I need to store which bools and which ints I want to check and their target values. Essentiall I have:
Dictionary <EmailNode,bool> selectedDependency;
Dictionary <some int variable in GameController ,bool> traitDependency;
Dictionary <some bool variable int GameController,bool> flagDependency;
int timeDependency;
and I need to be able to populate those dictionaries via the inspector in such a way that I can simply have an emailNode check its dependencies and return a bool representing wether or not they were met.
public bool checkDependencies(){
var cleared = true;
if (cleared == true) {
foreach (KeyValuePair<EmailNode, bool> entry in selectedDependency) {
if (entry.Key.selected != entry.Value) {
cleared = false;
break;
}
}
}
if (cleared == true) {
foreach (KeyValuePair<some int variable in GameController, bool> entry in traitDependency) {
//is int-x >= entry.value?
}
}
if (cleared == true) {
foreach (KeyValuePair<some bool variable int GameController, bool> entry in flagDependency) {
//is bool-x == to entry.Value?
}
}
if (cleared == true) {
var currentTime = 0;
if (timeDependency < currentTime) {
cleared = false;
}
}
return cleared;
}
Alas, the Dictionary class cannot be serialized by unity editor for use in an inspector. You will either need to create your own custom editor, or a serialize-able dictionary.
http://answers.unity3d.com/questions/460727/how-to-serialize-dictionary-with-unity-serializati.html
EDIT: P.S. You could also create an interface IN-GA$$anonymous$$E to enter dictionary values. Personally I hate working with the editor, sometimes creating an in-game interface is faster.