So I defined a data-holder class that contains a big number of primitive variables. For simplicity let’s say the class looks something like this:
public class Properties {
bool aBool;
float someFloat;
int anInteger;
}
I want to be able to attach any event to a set of conditions. As sourcecode this would look something like this:
public void CheckConditions(Properties properties) {
if (properties.aBool == true) {
//Run any Event
}
}
I don’t want to define those Conditions inside my source code for several reasons:
- The Conditions should be editable in a custom Editor window, without the need to touch any sourcecode.
- Sets of Conditions should be saved into and loaded from files.
So I started creating condition-classes for every variable inside the “Properties” class which became kind of confusing pretty fast.
Now I’m trying to figure a generic way to read out a list of all the variable names and their types defined in the dataholder class inside my sourcecode so i can define something like “Every number value can be checked for an input value being bigger, smaller, equal or unequal” and show these options in my UI. Later I want to be able to create condition-sets for pre-defined events in my Script without the need of defining a new variable in 5 different locations everytime a new one is created.
Shortly, I’m looking for a function that outputs all the variables inside the data-holder class as string-array for example.
And I need another function that gets the value inside the variable that matches the given (string) variable name.
I imagine something like this:
public struct Variable {
string name;
Type type;
}
public class Properties {
public Variable getVairables() {
// ... ?
}
public T getValue<T>(string varName) {
// ... ?
}
}
I wonder if Serializing is the right direction here, I saw some functions that seam to deal with - let me call it “variable variables” - but I’m not sure about that though.
Any suggestions on how to achive this are very welcome!
If this question has been answered allready please redirect me to any sources.
Thank you! And sorry for the lack of english skills