[英]Is there any solution for runtime code compilation in Unity3D for IL2Cpp builds?
I'm trying to compile C# code at runtime in Unity3D for IL2CPP build 64 bit Android.我正在尝试在运行时在 Unity3D 中为 IL2CPP 构建 64 位 Android 编译 C# 代码。
I have a string of code that I want to compile and execute dynamically.我有一串要动态编译和执行的代码。 The things that I've tried are:
我尝试过的事情是:
But what I got to understand is that all of the above doesn't work with IL2Cpp builds.但我要明白的是,以上所有内容都不适用于 IL2Cpp 构建。
The below code is carried out using: Second Github repo mentioned above.以下代码使用:上面提到的第二个 Github repo 执行。
CSScriptEngine engine = new CSScriptEngine();
engine.AddUsings("using UnityEngine; using System; using System.Collections.Generic;");
engine.AddOnCompilationFailedHandler(OnCompilationFail);
IScript result = engine.CompileCode(@codeToConvert);
With second plugin:使用第二个插件:
AndroidPlayer(ADB@127.0.0.1:34999) ArgumentException: Invalid path
at System.IO.Path.GetDirectoryName (System.String path) [0x00000] in <00000000000000000000000000000000>:0
at Mono.CSharp.DynamicLoader..ctor (Mono.CSharp.ReflectionImporter importer, Mono.CSharp.CompilerContext compiler) [0x00000] in <00000000000000000000000000000000>:0
at Mono.CSharp.Evaluator.Init () [0x00000] in <00000000000000000000000000000000>:0
at Mono.CSharp.Evaluator.Compile (System.String input, Mono.CSharp.CompiledMethod& compiled) [0x00000] in <00000000000000000000000000000000>:0
at Mono.CSharp.Evaluator.Evaluate (System.String input, System.Object& result, System.Boolean& result_set) [0x00000] in <00000000000000000000000000000000>:0
at Mono.CSharp.Evaluator.Run (System.String statement) [0x00000] in <00000000000000000000000000000000>:0
at UCompile.MonoEvaluator.Run (System.String scriptText) [0x00000] in <00000000000000000000000000000000>:0
at UCompile.CompilationUnit.Run (System.String code) [0x00000] in <00000000000000000000000000000000>:0
at UCompile.CSScriptEngine.AddUsings (System.String usings) [0x00000] in <00000000000000000000000000000000>:0
at CheckVersion.Operation_completed (UnityEngine.AsyncOperation obj) [0x00000] in <00000000000000000000000000000000>:0
at System.Action`1[T].Invoke (T obj) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.AsyncOperation.InvokeCompletionEvent () [0x00000] in <00000000000000000000000000000000>:0
You cannot use dynamic
keyword with IL2CPP - something about the way IL2CPP works.你不能在 IL2CPP 中使用
dynamic
关键字——这与 IL2CPP 的工作方式有关。 From what I hear, there will likely never be support for this with IL2CPP.据我所知,IL2CPP 可能永远不会支持这一点。
Cast to an explicit object and use that, instead, perhaps.转换为明确的 object 并使用它,也许。
More here: https://forum.unity.com/threads/dynamic-type-in-il2cpp.934338/更多信息: https://forum.unity.com/threads/dynamic-type-in-il2cpp.934338/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.