So I want to build this little code sandbox in Unity, which would allow me to teach students the basics of algorithmics and coding.
The idea would be for them to enter (very basic) code in a text box or something of the kind, and to observe the effects of their code onto objects present in a Unity scene. I’m pretty sure this has been done a million times, but I’d love to try my hand at this. The rub is, I have no idea where to start…
I guess the idea is that the string would be compiled into code & executed at runtime, at the press of a button.
I’ve read about numerous other questions on SO, and have come up with very diverse solutions such as using a C# parser, reflection, expression trees, CodeDom, etc.
From what I understood of all these (i.e., not much), CodeDom seemed more appropriate, but then I read that it only ran inside of Visual Studio and generated errors in public builds. So does that mean that this is going to be a problem within Unity3D (as it is based on Mono?)
I tested it and it works very well, but with one important flaw. It works in Unity editor but can’t be build due some error about lack of some Mono library.
This link on GitHub contains Unity project with working solution which works well both in Unity editor and build. Also it contains detailed explanation about why it have some complications during build and how author solved this problem.
The problem is, that second solution (in my opinion) is much harder to understand and work with. Besides that, I can’t figure out how to compile several scripts at once (not only one) and author of this solution is not very active on the forum.
Anyway, I recommend you to check both links and see how it made, also check various links provided by authors of this tools.