Hi there,
I would like to have some sort of stripped down script language for my map editor so that user can write some short pieces of code to extend the game with a little custom functionality that is very helpful here and there since it is usually hard to provide a GUI for everything. Is there already a “safe” way around here?
I mean I know the “eval()” method but this is potentially a risky operation since the user scripts are shared with other players using their maps…
I prefer CSharpCodeProvider, but how does it integrate into Unity? Can the resulting assemblies be used in WebPlayer for example? This class is not available there so only for PC versions, but then how would I get compiled scripts into Webplayer or Console versions?
Every other potentially simpler script language would also suffice provided that it works on all platforms in execution mode. Authoring these scripts would be ok being restricted to say PC platforms…
The last resort would be to immitate Unreal Kismet, but too much effort from my point of view…
regards
C.M.Burns
Directly compiling within the game could be difficult, but using a separate process to run GMCS and compile based on Interfaces you provide would be a safe, clean way to allow custom entry points into your Classes as well as a secure, more hack proof implementation on runtime class extensions.
I wrote a bit of helper for someone else:
http://forum.unity3d.com/threads/92922-build-unity-game-from-external-app
It should at least provide a method of attack if it`s the method you want to use.
The basic Idea would be to create a Stack of Interfaces that the user can Customize, and then they can separately create their own implementations of each interface and plug it in to the Corresponding objects. This way you can control what they interact with, while still providing global references and Singleton accesses, and allowing a full suite of Mono functionality within those limitations.
Thanks for your fast response!
Why could compiling in game be difficult? Couldn’t I just use a separate Thread?
I also noticed that the ability to load NET assemblies and also MethodInfo.DynamicInvoke() seem both to be available across all platforms so the C# compiler approach seems to be worth a try? But I am not sure:
Can the WebPlayer load NET assemblies that were added after the project has been built and execute code in them? I’d rather suspect the answer is no?!
But after all the Webplayer isn’t too important anyway…
Does anyone know how it looks like on consoles? Do they support the full NET classes in Unity (I mean the same like the PC versions) or only the subset?
Well the interface thing is also what I thought about although I’d also have to restrict the set of available mono classes to a safe one… But I am sure that is something that has been done already somewhere…
At the beginning I don’t even need that much of extensibility. Its more about custom number generators and conditional reaction on triggers and stuff.