ExpressionEvaluator - UnityEditor class

There is not much to say. I read the document but I couldn’t figure out how to use this info to evaluate an expression. Can someone put that info into an example?

I’m not sure what information you expect here. It just evaluates simple mathematical expressions. It only supports the operators: “+”, “-”, “*”, “/”, “%” and “^” as well as brackets “(”, “)” . It only supports literals as operands. So no support for variables or any kind of “functions”. Since it’s an editor class it can only be used in editor scripts.

I don’t have the latest Unity version and in my version this class is still internal. I guess it’s meant to evaluate the input string in number fields to directly convert an expression into a number. So when you enter 11/32 into the inspector it should directly convert to 0.34375.

A simple example is this:

float f = ExpressionEvaluator.Evaluate<float>("(3+2)*7 - 5^2");

Here “f” should contain the number 10.0f.

If you need something more advanced you may want to have a look at my ExpressionParser on the wiki. It actually creates an expression tree which can be evaluated later multiple times. It also supports functions and (input) variables. Of course this class is not limited to editor code. It can be used in a build as well. It will work on all platforms.