unity-ilruntime热更新


title: unity-ilruntime热更新
categories: Unity3d
tags: [unity, ilruntime, 热更新]
date: 2022-07-10 12:22:04
comments: false
mathjax: true
toc: true

unity-ilruntime热更新


前篇

  • 官网

    • github - https://github.com/Ourpalm/ILRuntime

    • 中文官网 - https://ourpalm.github.io/ILRuntime/public/v1/guide/index.html

    • demo - https://github.com/Ourpalm/ILRuntimeU3D/

  • Unity 接入 ILRuntime 热更方案 - https://www.jianshu.com/p/e7283e1ed86a

  • Unity ILRuntime热更框架保姆级教程(一) - https://zhuanlan.zhihu.com/p/495487812

  • 临上线项目使用ILRuntime热更 - https://blog.51cto.com/zhaoqingqing/3146140

  • ILRuntime来实现热更新的优与劣 - http://ourpalm.github.io/ILRuntime/public/v1/guide/tutorial.html

  • 关于热更新,大家现在都是怎么实现的? - https://answer.uwa4d.com/question/5a9fc420d35eb22c10a0a365

  • ILRuntime:用寄存器模式吊打Lua - https://zhuanlan.zhihu.com/p/538437458


从 0 运行 helloworld

这里使用的 unity 版本为 2019.4.38f1

主要参考: Unity ILRuntime热更框架保姆级教程(一) - https://zhuanlan.zhihu.com/p/495487812

前置条件

  1. 安装 .net4.6.x 的开发包

    地址: https://dotnet.microsoft.com/en-us/download/visual-studio-sdks,

  2. 安装 rider 编辑器

    用于编辑 热更工程 代码


步骤

  1. 创建一个新工程 TestILRuntime

    edit -> project settings -> player, 修改 .net 版本为 4.x, 勾选上 allow unsafe code

    image-20220710141600237

  2. git 拉取 https://github.com/Ourpalm/ILRuntimeU3D/ 项目, 并将 Assets 目录下的 ILRuntime,Plugins,Samples,StreamingAssets 这几个目录拷贝到新工程的 Assets

  3. 使用 rider 打开热更工程修改打码测试

    1. 热更工程目录 Assets\Samples\ILRuntime\2.0.2\Demo\HotFix_Project~ (unity 编辑器忽略了 ~ 结尾的文件夹)

      • 可能会遇到 .net 对应版本没安装的情况

        image-20220710133357055

        右键 模块 -> properties -> application -> target framework, 选择已有的版本即可 (最好安装上工程要求的版本 .net 4.6.x)

        image-20220710142226613

  4. 修改代码测试一下

    1. Assets/Samples/ILRuntime/2.0.2/Demo/_Scenes/Examples/01_HelloWorld.unity 场景为例, 里面就挂了一个 01_HelloWorld/HelloWorld.cs 测试脚本, 里面加载了 Assets/StreamingAssets/HotFix_Project.dll 文件, 也就是 热更工程 HotFix_Project~ 构建出来的库, 加载完后调用了 OnHotFixLoaded 方法调用测试代码

      void OnHotFixLoaded() {
              
              
          //HelloWorld,第一次方法调用
          appdomain.Invoke("HotFix_Project.InstanceClass", "StaticFunTest", null, null);
      }
      
    2. 修改 热更工程 中的对应的方法

      image-20220710143335051

      然后构建 dll 库

      image-20220710143443486

      导出文件 Assets/StreamingAssets/HotFix_Project.dll

      image-20220710143845222

      • 可以从模块配置中看到 导出目录编译宏 等编译配置

        image-20220710150609502

  5. 启动 unity

    成功看到修改后的内容

    image-20220710144000990


猜你喜欢

转载自blog.csdn.net/yangxuan0261/article/details/125706095