Beispiel #1
0
    public static void GenerateCLRBindingByAnalysis()
    {
        //GenerateCLRBinding();

        //用新的分析热更dll调用引用来生成绑定代码
        ILRuntime.Runtime.Enviorment.AppDomain appdomain = new ILRuntime.Runtime.Enviorment.AppDomain();

        string path = Application.dataPath.Replace("Assets", "/Library/ScriptAssemblies/hotfix.dll");

        if (!File.Exists(path))
        {
            Debug.LogError("需要先创建dll(描述文件) 然后编译完后再来生成!");

            //需要先创建dll 然后编译完后再来生成
            //DllTools.CreateDll();
        }

        using (FileStream fs = new FileStream("Assets/../Library/ScriptAssemblies/hotfix.dll", FileMode.Open, FileAccess.Read))
        {
            appdomain.LoadAssembly(fs);

            ILAdaptor.RegisterAdaptor(appdomain);                          //跨域继承适配器的注册
            ILDelegate.RegisterDelegate(appdomain);                        //委托适配器

            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain); //LitJson重定向


            ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(appdomain, "Assets/Script/Main/ILBinding");
            AssetDatabase.Refresh();
        }
    }
    /// <summary> 初始化ILRuntime </summary>
    public void InitializeILRuntime()
    {
#if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE)
        //由于Unity的Profiler接口只允许在主线程使用,为了避免出异常,需要告诉ILRuntime主线程的线程ID才能正确将函数运行耗时报告给Profiler
        appdomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId;
#endif
        //这里做一些ILRuntime的注册

        ILAdaptor.RegisterAdaptor(appdomain);   //跨域继承适配器的注册
        ILDelegate.RegisterDelegate(appdomain); //委托适配器

        //LitJson重定向
        LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);

        //这个是只有生成了绑定代码之后 才能够调用的
        //ILRuntime.Runtime.Generated.CLRBindings.Initialize(appdomain);
    }