3

我正在尝试在 Unity3D 中为 IL2CPP 构建 64 位 Android 在运行时编译 C# 代码。

我有一串要动态编译和执行的代码。我尝试过的事情是:

  1. https://github.com/aeroson/mcs-ICodeCompiler
  2. https://github.com/SoapCode/UCompile/tree/master/Assets/UCompile
  3. https://assetstore.unity.com/packages/tools/integration/roslyn-c-runtime-compiler-142753#reviews

但我要明白的是,以上所有内容都不适用于 IL2Cpp 构建。

下面的代码是使用:上面提到的第二个 Github repo 执行的。

CSScriptEngine engine = new CSScriptEngine();
engine.AddUsings("using UnityEngine; using System; using System.Collections.Generic;");
engine.AddOnCompilationFailedHandler(OnCompilationFail);
IScript result = engine.CompileCode(@codeToConvert);

使用第二个插件:

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
4

0 回答 0