gpt4 book ai didi

c# - Unity3D 中是否有针对 IL2Cpp 构建的运行时代码编译的解决方案?

转载 作者:行者123 更新时间:2023-12-05 07:17:57 28 4
gpt4 key购买 nike

我正在尝试在运行时在 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 存储库执行的。

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

最佳答案

您不能将 dynamic 关键字与 IL2CPP 一起使用 - 与 IL2CPP 的工作方式有关。据我所知,IL2CPP 可能永远对此提供支持。

转换成一个显式对象并使用它,也许吧。

更多信息:https://forum.unity.com/threads/dynamic-type-in-il2cpp.934338/

关于c# - Unity3D 中是否有针对 IL2Cpp 构建的运行时代码编译的解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58568437/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com