分享

ILRuntime第一课HelloWorld

 柠檬榆 2017-11-06
using ILRuntime.Runtime.Enviorment;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HelloWorld : MonoBehaviour {
    AppDomain appdomain;
    void Start()
    {
        StartCoroutine(LoadHotFixAssembly());
    }
    IEnumerator LoadHotFixAssembly() {
        appdomain = new ILRuntime.Runtime.Enviorment.AppDomain();
        //加载DLL文件
#if UNITY_ANDROID
        WWW www = new WWW(Application.streamingAssetsPath + "/HotFix_TestProject.dll");
#else
        WWW www = new WWW("file:///" + Application.streamingAssetsPath + "/HotFix_TestProject.dll");
#endif
        while (!www.isDone)//如果资源未加载完
            yield return null;
        if (!string.IsNullOrEmpty(www.error))
            Debug.LogError(www.error);
        byte[] dll = www.bytes;
        www.Dispose();
        //加载PDB文件
#if UNITY_ANDROID
        www = new WWW(Application.streamingAssetsPath + "/HotFix_TestProject.pdb");
#else
        www = new WWW("file:///" + Application.streamingAssetsPath + "/HotFix_TestProject.pdb");
#endif
        while (!www.isDone)
            yield return null;
        if (!string.IsNullOrEmpty(www.error))
            Debug.LogError(www.error);
        byte[] pdb = www.bytes;
        using (System.IO.MemoryStream fs=new System.IO.MemoryStream(dll)) {
            using (System.IO.MemoryStream p=new System.IO.MemoryStream(pdb)) {
                appdomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider());
            }
        }
        InitializeILRuntime();
        OnHotFixLoaded();
    }
    //初始化,注册
    void InitializeILRuntime()
    {
    }
    //调用
    void OnHotFixLoaded() {
        appdomain.Invoke("HotFix_TestProject.InstanceClass""StaticFunTest"null,null);
    }
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多