On Unity3D there is something called "UnityEvent". I can call any method on any instance of any class, as long as the method is public. It has nice GUI, too.
public class MyEventType : UnityEvent { }
public MyEventType OnEvent;
void Main(){
OnEvent.Invoke();
}
What I'm trying to accomplish is to make a quest and dialogue systems. So far, I can use this thing for triggering events scripted somewhere else. But, I also need something that will check some variables if their value is lesser, smaller, equal, smaller or equal, lesser or equal than any given value or a different variable.
For example: Our hero comes to a hospital. He talks with a doctor. Dialogue controller has to check if player's health (accesible with character.stats.currentHP) is smaller than his max health (character.stats.maxHP), and if so, an option appears on the screen "What's up doc?".
Of course, I could use different script for every dialogue option, and it would be simpler, but the point is to let somebody who has no idea how to write code (like me) build missions and dialogues. I've thought about system.reflection, and have no idea how to make it work.
Problem solved with System.Reflection, all I needed to understand how to do what I need to do was reading documentation over and over until I understood it. Apparently almost all I needed was to make a list of such classes in pairs:
public class FieldReference
{
public GameObject gObject;
public string component;
public string fieldName;
public string value {
get {
return gObject.GetComponent (component).GetType ().GetField (fieldName).GetValue (gObject.GetComponent (component)).ToString ();
}
}
}
write some code to compare them and a custom inspector editor.
I should read documentation more often.