少年修仙传客户端基础资源
lwb
2021-03-04 91b3000be47471608ec16b2ce1df1c0397c12451
Assets/ILRuntime/Src/ILRuntimeUtility.cs
@@ -1,39 +1,56 @@
using System.IO;
using ILRuntime.Mono.Cecil.Pdb;
using ILRuntime.Runtime.Enviorment;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class ILRuntimeUtility : SingletonMonobehaviour<ILRuntimeUtility>
class ILRuntimeUtility : Singleton<ILRuntimeUtility>
{
    private AppDomain appdomain;
    public void Init()
    {
        LoadILRuntime();
    }
    void LoadILRuntime()
    {
        appdomain = new AppDomain();
        var dllPath = string.Empty;
        var pdbPath = string.Empty;
        if (AssetSource.refdataFromEditor)
        {
            dllPath = ResourcesPath.ResourcesOutAssetPath + "logic/LogicProject.bytes";
            pdbPath = ResourcesPath.ResourcesOutAssetPath + "logic/LogicProject.pdb";
    public ILRuntime.Runtime.Enviorment.AppDomain appdomain {
        get {
            return ILLauncherProxy.Instance.appdomain;
        }
        else
        {
            dllPath = AssetVersionUtility.GetAssetFilePath("logic/LogicProject.bytes");
            pdbPath = AssetVersionUtility.GetAssetFilePath("logic/LogicProject.pdb");
        }
        var fs = new FileStream(dllPath, FileMode.Open);
        var p = new FileStream(pdbPath, FileMode.Open);
        appdomain.LoadAssembly(fs, p, new PdbReaderProvider());
    }
    public void LaunchStart()
    public void AddEvent(string modelName, string eventName, Action action)
    {
        appdomain.Invoke("LogicProject.ILTest", "Test", null, null);
        var iType = appdomain.LoadedTypes[modelName];
        var get_Instance = iType.GetMethod("get_Instance", 0);
        var instance = appdomain.Invoke(get_Instance, null);
        var type = iType.ReflectionType;
        var eventInfo = type.GetEvent(eventName);
        eventInfo.AddEventHandler(instance, action);
    }
}
    public void RemoveEvent(string modelName, string eventName, Action action)
    {
        var iType = appdomain.LoadedTypes[modelName];
        var get_Instance = iType.GetMethod("get_Instance", 0);
        var instance = appdomain.Invoke(get_Instance, null);
        var type = iType.ReflectionType;
        var eventInfo = type.GetEvent(eventName);
        eventInfo.RemoveEventHandler(instance, action);
    }
    public void ModelInvoke(string modelName, string methodName, params object[] p)
    {
        var iType = appdomain.LoadedTypes[modelName];
        var get_Instance = iType.GetMethod("get_Instance", 0);
        var method = iType.GetMethod(methodName, p.Length);
        var instance = appdomain.Invoke(get_Instance, null);
        appdomain.Invoke(method, instance, p);
    }
    public T ModelInvoke<T>(string modelName, string methodName, params object[] p)
    {
        var iType = appdomain.LoadedTypes[modelName];
        var get_Instance = iType.GetMethod("get_Instance", 0);
        var method = iType.GetMethod(methodName, p.Length);
        var instance = appdomain.Invoke(get_Instance, null);
        return (T)appdomain.Invoke(method, instance, p);
    }
}