I'm making a game in Unity that would feature a sort of simplified coding in which the player would steadily automate various parts of the game's management.
Mockup of what I'm trying to make
Here's some pseudocode using pseudo-reflection that will hopefully clarify things further:
public class ProductionScript:MonoBehaviour{
public int targetNumberOfProductionFacilities;
void onGameTick(){ BuildOrDestroyProductionFacilities(targetNumberOfProductionFacilities) }
public void ModifyTargetNumber(int number){//called from UI
targetNumberOfProductionFacilities=number;
}
}
public class VariableRepresentation{ public FieldInfo variableInfo; }
public class VisualScriptingManager:MonoBehaviour{
public VariableRepresentation variableRepresentationPrefab;
List<VariableRepresentation> variableRepresentations=new List<VariableRepresentation>();
void InstantiateVariableRepresentation(EventData underMouseClick){
variableRepresentations.Add(Instantiate(variableRepresentationPrefab));
variableRepresentations[variableRepresentations.Count-1].variableInfo=Assembly.GetVariable(underMouseClick.getComponent<ProductionScript>().targetNumberOfProductionFacilities) //hardcoded for demonstration
}
void onGameTick(){
foreach (VariableRepresentation rep in variableRepresentations) {
rep.variableInfo.SetValue(Calculate(variableRepresentations()));
//this would solve the math of whatever configurations the player saved and would
update the value of the variable in question, wherever it is located
}
}
I might be completely wrong in assuming that reflection is the way to go for this sort of a system. A few people have suggested an expression tree or a virtual machine. What would be the most elegant thing to use in order to make a system like this? I don't want to waste time researching something that is unable or unlikely to create a system like this.
Aucun commentaire:
Enregistrer un commentaire