开发者

The mechanism behind Unity3D visual programming third party tools

First sorry for posting this here.I just got no answer to this question on "Unity Answers"I have been looking into the tools like uScript or Strumpy Shader Editors which are node based visual programming tools like Unreal Kismet or 3DsMax particle flow system. I have been researching on how in fact these tools generate the source code in Unity.So I assume that during the node logic assembly the code should be generated and compiled to DLLs (in Unity all the source code is compiled into DLLs)dynamically.I started looking into such C# assemblies like Reflections , Microsoft.CSharp and System.CodeDom.Compiler; I even tried to write a C# class in Unity via the editor as a text and then parse and compile it into DLL using th开发者_开发问答e above mentioned tools(it was ok but the DLL was existing only during the Runtime in the temp..) Therefore I would like to know is this the approach those tools are likely to use? Or there is a better and cleaner way to do it ?Thanks .


I'm actually in the process of doing the same thing.. I think you are on the right path with the Compiler classes. I dont think you can emit IL on the fly on mobile devices as a security sandbox issue but I'm dynamically creating c# code and compiling it into persistent dll's like this..

CompilerParameters compilerParameter = new CompilerParameters();
compilerParameter.OutputAssembly = "/Your/Path/Here.dll";
CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider("CSharp");

StringBuilder code = new StringBuilder();
code.AppendLine("public static class Test {");
//More code here...
code.AppendLine("}");
var compilerResult = codeDomProvider.CompileAssemblyFromSource(compilerParameter, code.ToString());

Hope this helps..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜