I’m using Unity with C#. Creating a resource management game.
I need an Index system. ie. Food Happiness index, Food Variety idex.
Each index would have different formulas.
I don’t want to hardcode each indexes.
I’m looking for parsing solutions that would allow me to store the formulas as string in JSON. And evaluate these formulas during runtime.
foodhapiness = (resourceDic["food"].Production/esourceDic["food"].Consumption) * foodVariety;
foodVariety = resourceDic["fish"].count/resourceDic["meat"].count;
Also, I’m thinking of letting user add their own indexes as well. - Create text file(json) with formulas and the game should load the text file and evaluate. Like a mod.
I tried using several Expression Evaluator solutions which would have been the solution but they appear to not be working with Unity.
- FLEE : Error at compile. FileNotFoundException: Could not load file or assembly 'Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
- C# Expression Evaluator : Won’t compile. This one Unity says something like can’t load library bundle.
In Javascript, there’s an Eval() function. But someone pointed out that it’s risky since this allow user to run any function also I need C# solution.
It feels like I’m coming at this in the wrong way. Anyone have a better solution for something like this ?