赞
踩
HyBridCLR文档地址:HyBridCLR
在看本文章之前,建议先把HyBridCLR文档全部浏览一遍,否则会忽视掉很多细节。
Unity编辑器必须选择 Windows Build Support(IL2CPP)或Mac Build Support(IL2CPP)。
Windows: Win下需要安装visual studio 2019或更高版本。安装时至少要包含 使用Unity的游戏开发 和 使用c++的游戏开发 组件。安装git
Mac: 要求MacOS版本 >= 12,xcode版本 >= 13,例如xcode 13.4.1, macos 12.4。
安装 git
gitee: https://gitee.com/focus-creative-games/hybridclr_unity.git
github:https://github.com/focus-creative-games/hybridclr_unity.git。
任选其一,输入,回车。
说明导入成功!
下载成功!
将热更新DLL放入HyBridCLRSetting中
完成后会显示一个文件夹,表示成功!:
创建脚本LoadDll.cs,并挂在场景物体上。
using System; using System.IO; using System.Reflection; using UnityEngine; using System.Linq; public class LoadDll : MonoBehaviour { // Start is called before the first frame update private string hotUpdateDllName = "MySqlite"; void Start() { // Editor环境下,HotUpdate.dll.bytes已经被自动加载,不需要加载,重复加载反而会出问题。 #if !UNITY_EDITOR Assembly hotUpdateAss = Assembly.Load(File.ReadAllBytes($"{Application.streamingAssetsPath}/{hotUpdateDllName}.dll.bytes")); #else // Editor下无需加载,直接查找获得HotUpdate程序集 Assembly hotUpdateAss = System.AppDomain.CurrentDomain.GetAssemblies().First(a => a.GetName().Name == hotUpdateDllName); #endif Type type = hotUpdateAss.GetType("HotUpdate"); type.GetMethod("Set").Invoke(null, null); } }
在MySqlite热更程序集下创建热更脚本HotUpdate.cs,也挂在场景物体上
using UnityEngine;
public class HotUpdate : MonoBehaviour
{
public static void Set()
{
Debug.Log("第一次打印");
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。