【Roslyn C#】Runtime环境Unity读取字符串代码

2021-09-13 04:13

阅读:910

标签:private   world   arp   deb   art   sha   src   compile   from   Roslyn C#         下载地址:https://files-cdn.cnblogs.com/files/sanyejun/RoslynC_RuntimeCompiler.zip 使用示例 using System.Collections; using System.Collections.Generic; using RoslynCSharp; using UnityEngine; public class Example : MonoBehaviour { private ScriptDomain domain = null; //创建字符串代码 private string source = "using UnityEngine;" + "class Test : MonoBehaviour" + "{" + " void SayHello()" + " {" + " Debug.Log(\"Hello World\");" + " }" + "}"; // Start is called before the first frame update void Start() { // Create the domain - We are using C# code so we need the compiler domain = ScriptDomain.CreateDomain("MyTestDomain", true); // Compile and load the source code ScriptType type = domain. CompileAndLoadMainSource(source); // We need to pass a game object because ‘Test‘ inherits from MonoBehaviour ScriptProxy proxy = type.CreateInstance(gameObject); // 调用字符串的 SayHello 方法 proxy.Call("SayHello"); } }  【Roslyn C#】Runtime环境Unity读取字符串代码标签:private   world   arp   deb   art   sha   src   compile   from   原文地址:https://www.cnblogs.com/sanyejun/p/14899043.html

上一篇:flume

下一篇:js中的对象数据类型


评论


亲,登录后才可以留言!