I’m creating a project based on user created content, including visual scripting tool for creating complex interactive objects and scenes.
After some research I found few possible solutions and two of them seem to be what I need but there is always a downside to them.
1) Dynamic compilation using classes like Mono.CSharp.CSharpCodeProvider. But it seems like nobody can get it work in Build. Or Microsoft.CSharp.dll just doesn’t want to work in unity. I’m sure I’m missing something there. I would really like to see this working.
2) Emitting dynamic methods using System.Reflection.Emit. Pretty complex, but besides that looks perfect. But, I’m not sure about the performance of this approach. Reflection.Emit is unavailable in Web Player (not crucial). And my biggest concern is that in the future unity IL2CPP won’t support Reflection.Emit.
3…) I’ve just learned that eval() compiles code on the fly only the first time the code executed and not interpreted every time as I thought, I’ll take a second look into that. And it looks like eval() can create a persistent code. Playing around with it. http://tools.garry.tv/unityeval/ If the performance is OK, it might work for me.
And of course first two (what about third?) examples leave the door wide open for all kinds of hacks? Also I wonder how anticheat software will perceive those kinds of operations.
I’m not sure about scripting solutions like LUA, they seem to show not a greatest performance and I will have to build my own visual scripting system on top and it’s going to be ugly.
I’ve tried making my runtime behaviour generation system based on delegates, but it is weird and clunky and even the most generous benchmarking gives it performance about 1/4th of the Unity script’s performance. How realistic is it to create such thing with a high level language like unity pseudo C#?
Did I miss anything? I’m looking for your advice on how to go about implementing my scripting system.