简体   繁体   English

对于 IL2Cpp 构建,Unity3D 中是否有运行时代码编译的解决方案?

[英]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:我尝试过的事情是:

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

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.

相关问题 Unity3D的IL2CPP模式下如何通过P/Invoke使用IFileDialog COM接口? - How to use IFileDialog COM Interface by P/Invoke in IL2CPP mode of Unity3D? 如何将纯C ++代码与IL2CPP一起用于Unity编译为Windows应用程序? - How to use pure C++ code with IL2CPP for Unity compilation into windows application? 列表的 DataContractSerializer 失败<bool>在 Android 上使用 Unity3d 的 IL2CPP 编译时出现“未生成提前 (AOT) 代码”错误</bool> - DataContractSerializer fails for List<bool> on Android when compiled using Unity3d's IL2CPP with "no ahead of time (AOT) code was generated" error 由于 IL2CPP,Unity 无法构建 - Unity fails to build due to IL2CPP 使用 IL2CPP 在 Visual Studio 中调试 Unity Hololens? - Unity Hololens debugging in Visual Studio with IL2CPP? Google.Protobuf.Reflection 不适用于 Unity 中的 il2cpp 脚本 - Google.Protobuf.Reflection is not working with il2cpp scripting in Unity Unity 项目仅适用于 IL2CPP 上的 Development Build - Unity Project works only in Development Build on IL2CPP iOS上的Unity 5.1序列化-尚不支持IL2CPP文件名 - Unity 5.1 serialization on iOS - IL2CPP Filename not supported yet 使用 IL2CPP 在 Unity 中构建 Android App Bundle 的错误和失败 - Errors and failure building Android App Bundle in Unity with IL2CPP 由于 IL2CPP 问题,Unity 无法构建 Unity 2019.2.17f1 - Unity Can not Build because of IL2CPP Problem Unity 2019.2.17f1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM