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 );
}
}
|