zoukankan      html  css  js  c++  java
  • 【Roslyn C#】Runtime环境Unity读取字符串代码

    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");
        }
        
    }
  • 相关阅读:
    原生JS实现简易随机点名功能
    react 字父组件传值
    关于react组件传值问题
    轮波图
    烟花
    this的详解
    封装多元素多属性的链式缓冲
    留言板设计的流程,拖动窗口
    运动的小球
    运动的小球自动变键盘控制
  • 原文地址:https://www.cnblogs.com/sanyejun/p/14899043.html
Copyright © 2011-2022 走看看