打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ILRuntime第一课HelloWorld
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);
    }
}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
IIS Web 服务器/ASP.NET 运行原理基本知识概念整理
VS中Release模式下生成去掉生成pdb文件
VS2010/MFC编程入门之二(利用MFC向导生成单文档应用程序框架)
Revit二次开发
MT4调用C++ dll实例
Unity 热更新技术 | (一) 热更新的基本概念原理及主流热更新方案介绍
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服