一、启动ILRuntime并加载程序集
public class Lesson02 : MonoBehaviour
{
private AppDomain _domain;
private MemoryStream _dllStream;
private MemoryStream _pdbStream;
IEnumerator Start()
{
_domain = new AppDomain();
_domain.UnityMainThreadID = Thread.CurrentThread.ManagedThreadId;
//请求Dll
#if UNITY_ANDROID
UnityWebRequest dllReq = UnityWebRequest.Get(Application.streamingAssetsPath + "/HotFix_Project.dll");am = new MemoryStream();
#else
UnityWebRequest dllReq = UnityWebRequest.Get("file:///" + Application.streamingAssetsPath + "/HotFix_Project.dll");
#endif
yield return dllReq.SendWebRequest();
if(dllReq.result != UnityWebRequest.Result.Success)
Debug.Log("加载Dll错误!");
byte[] dllBuffer = dllReq.downloadHandler.data;
dllReq.Dispose();
//请求Pdb
#if UNITY_ANDROID
UnityWebRequest pdbReq = UnityWebRequest.Get(Application.streamingAssetsPath + "/HotFix_Project.pdb");am = new MemoryStream();
#else
UnityWebRequest pdbReq = UnityWebRequest.Get("file:///" + Application.streamingAssetsPath + "/HotFix_Project.pdb");
#endif
yield return pdbReq.SendWebRequest();
if (pdbReq.result != UnityWebRequest.Result.Success)
Debug.Log("加载Pdb错误!");
byte[] pdbBuffer = pdbReq.downloadHandler.data;
pdbReq.Dispose();
_dllStream = new MemoryStream(dllBuffer);
_pdbStream = new MemoryStream(pdbBuffer);
_domain.LoadAssembly(_dllStream,_pdbStream,new PdbReaderProvider());
print("加载成功!!!");
}
private void OnDestroy()
{
if(_domain != null)
{
_domain.Dispose(
文章来源地址https://www.toymoban.com/news/detail-526296.html
文章来源:https://www.toymoban.com/news/detail-526296.html
到了这里,关于Unity ILRuntime热更新(二)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!