示例#1
0
    //生成clr绑定
    static public void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin, string dllpath = "")
    {
        if (platform == RuntimePlatform.Lumin)
        {
            platform = Application.platform;
        }
        //默认读StreammingAssets下面path
        if (dllpath == "")
        {
            dllpath = Application.streamingAssetsPath + "/" + BDUtils.GetPlatformPath(platform) + "/hotfix/hotfix.dll";
        }

        //不参与自动绑定的
        List <Type> notGenerateTypes = new List <Type>()
        {
            typeof(MethodBase), typeof(MemberInfo), typeof(FieldInfo), typeof(MethodInfo), typeof(PropertyInfo)
            , typeof(Component), typeof(Type)
        };


        //用新的分析热更dll调用引用来生成绑定代码

        ILRuntimeHelper.LoadHotfix(dllpath, false);

        BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, "Assets/Code/Game/ILRuntime/Binding/Analysis", notGenTypes: notGenerateTypes);

        ILRuntimeHelper.Close();
        AssetDatabase.Refresh();

        //暂时先不处理
    }
 //生成clr绑定
 static void GenCLRBindingByAnalysis()
 {
     //用新的分析热更dll调用引用来生成绑定代码
     ILRuntimeHelper.LoadHotfix(false);
     BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, "Assets/Code/Game/ILRuntime/Binding");
     AssetDatabase.Refresh();
 }
    /// <summary>
    /// 分析dll生成
    /// </summary>
    /// <param name="platform"></param>
    /// <param name="dllpath"></param>
    static private void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin, string dllpath = "")
    {
        if (platform == RuntimePlatform.Lumin)
        {
            platform = Application.platform;
        }

        //默认读StreammingAssets下面path
        if (dllpath == "")
        {
            dllpath = Application.streamingAssetsPath + "/" + BApplication.GetPlatformPath(platform) + DLLPATH;
        }

        //不参与自动绑定的
        List <Type> excludeTypes = new List <Type>(); //

        excludeTypes.AddRange(manualBindingTypes);
        excludeTypes.AddRange(preBindingTypes);

        //用新的分析热更dll调用引用来生成绑定代码
        var targetPath = "Assets/Code/Game/ILRuntime/Binding/Analysis";

        ILRuntimeHelper.LoadHotfix(dllpath, false);
        BindingCodeGenerator.GenerateAnalysisBindingCode(ILRuntimeHelper.AppDomain, targetPath,
                                                         blackTypes: excludeTypes);

        ILRuntimeHelper.Close();
        AssetDatabase.Refresh();
        //暂时先不处理
    }
示例#4
0
    //生成clr绑定
    public static void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin, string dllpath = "")
    {
#if ILRUNTIME
        if (platform == RuntimePlatform.Lumin)
        {
            platform = Application.platform;
        }
        //默认读StreammingAssets下面path
        if (dllpath == "")
        {
            dllpath = Application.streamingAssetsPath + "/" + DLLPATH;
        }

        //不参与自动绑定的
        List <Type> notGenerateTypes = new List <Type>()
        {
            typeof(MethodBase), typeof(MemberInfo), typeof(FieldInfo), typeof(MethodInfo), typeof(PropertyInfo)
            , typeof(Component), typeof(Type)
        };


        //用新的分析热更dll调用引用来生成绑定代码


        ILRuntimeHelper.LoadHotfix(dllpath, false);
        BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, "Assets/LWFramework/ILRuntime/Binding/Analysis", notGenTypes: notGenerateTypes);
        ILRuntimeHelper.Close();
        AssetDatabase.Refresh();
#else
        Debug.Log("当前不是IL模式");
#endif


        //暂时先不处理
    }
    //生成clr绑定
    static public void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin)
    {
        if (platform == RuntimePlatform.Lumin)
        {
            platform = Application.platform;
        }

        //用新的分析热更dll调用引用来生成绑定代码
        var dllpath = Application.streamingAssetsPath + "/" + BDUtils.GetPlatformPath(platform) + "/hotfix/hotfix.dll";

        ILRuntimeHelper.LoadHotfix(dllpath, false);
        BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain,
                                                 "Assets/Code/Game/ILRuntime/Binding/Analysis");
        AssetDatabase.Refresh();
        return;

        //暂时先不处理
        var assemblies = new List <Assembly>()
        {
            typeof(UnityEngine.UI.Button).Assembly,
        };
        var types = new List <Type>();

        types.Add(typeof(Vector4));
        //
//        foreach (var assm in assemblies)
//        {
//            var _ts = assm.GetTypes();
//            foreach (var t in _ts)
//            {
//                if (t.Namespace != null)
//                {
//                    if (t.FullName.Contains("UnityEngine.Android")
//                        || t.FullName.Contains("UnityEngine.iPhone")
//                        || t.FullName.Contains("UnityEngine.WSA")
//                        || t.FullName.Contains("UnityEngine.iOS")
//                        || t.FullName.Contains("UnityEngine.Windows")
//                        || t.FullName.Contains("JetBrains")
//                        || t.FullName.Contains("Editor"))
//                    {
//                        continue;
//                    }
//                }
//
//
//                types.Add(t);
//            }
//        }
//
//        types = types.Distinct().ToList();
        //PreBinding
        BindingCodeGenerator.GenerateBindingCode(types, "Assets/Code/Game/ILRuntime/Binding/PreBinding");
        AssetDatabase.Refresh();
    }
        //生成clr绑定
        private static void GenClrBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin)
        {
            if (platform == RuntimePlatform.Lumin)
            {
                platform = Application.platform;
            }

            //用新的分析热更dll调用引用来生成绑定代码
            var dllpath = Application.streamingAssetsPath + "/AssetBundles/" + AssetBundleSettings.GetPlatformForAssetBundles(platform) +
                          "/hotfix.dll";

            ILRuntimeHelper.LoadHotfix(dllpath, false);
            BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain,
                                                     "Assets/" + ILRuntimeScriptSetting.Default.GenClrBindPath.CreateDirIfNotExists());
            AssetDatabase.Refresh();
        }
    //生成clr绑定
    static void GenCLRBindingByAnalysis()
    {
        //用新的分析热更dll调用引用来生成绑定代码
        ILRuntimeHelper.LoadHotfix(Application.streamingAssetsPath, false);
        BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain,
                                                 "Assets/Code/Game/ILRuntime/Binding/Analysis");
        AssetDatabase.Refresh();
        return;

        //暂时先不处理
        //预先绑定所有的
        var assemblies = new List <Assembly>()
        {
            typeof(UnityEngine.UI.Button).Assembly,
        };
        var types = new List <Type>();

        //
        foreach (var assm in assemblies)
        {
            var _ts = assm.GetTypes();
            foreach (var t in _ts)
            {
                if (t.Namespace != null)
                {
                    if (t.FullName.Contains("UnityEngine.Android") ||
                        t.FullName.Contains("UnityEngine.iPhone") ||
                        t.FullName.Contains("UnityEngine.WSA") ||
                        t.FullName.Contains("UnityEngine.iOS") ||
                        t.FullName.Contains("UnityEngine.Windows") ||
                        t.FullName.Contains("JetBrains") ||
                        t.FullName.Contains("Editor"))
                    {
                        continue;
                    }
                }


                types.Add(t);
            }
        }

        types = types.Distinct().ToList();
        //PreBinding
        BindingCodeGenerator.GenerateBindingCode(types, "Assets/Code/Game/ILRuntime/Binding/PreBinding");
        AssetDatabase.Refresh();
    }
示例#8
0
    /// <summary>
    /// 开始启动游戏
    /// </summary>
    private void OnLaunch()
    {
        if (IsCodeHotfix) //热更代码模式
        {
            ILRuntimeHelper.LoadHotfix(IsLoadPdb);

            ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null, new object[] { IsCodeHotfix, IsAssetBundleModel });
        }
        else
        {
            //这里用反射是为了 不访问逻辑模块的具体类,防止编译失败
            var assembly = Assembly.GetExecutingAssembly();
            var type     = assembly.GetType("BDLauncherBridge");
            var method   = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
            method.Invoke(null, new object[] { IsCodeHotfix, IsAssetBundleModel });
        }
    }
示例#9
0
    // Use this for initialization
    private void Awake()
    {
        this.gameObject.AddComponent <IEnumeratorTool>();
        this.gameObject.AddComponent <BResources>();

        if (IsCodeHotfix)
        {
            ILRuntimeHelper.LoadHotfix(IsLoadPdb);

            ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null, new object[] { IsCodeHotfix, IsResourceHotfix });
        }
        else
        {
            //这里用反射是为了 不访问逻辑模块的具体类,防止编译失败
            var assembly = Assembly.GetExecutingAssembly();
            var type     = assembly.GetType("BDLauncherBridge");
            var method   = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
            method.Invoke(null, new object[] { IsCodeHotfix, IsResourceHotfix });
        }
    }
示例#10
0
        // 加載 dll
        // isregisterBindings 為 false 時,是生成 binding的時候
        private void LoadDll(string dllPath, bool isRegisterBindings = true)
        {
            switch (ILRuntimeScriptSetting.Default.HotfixRunMode)
            {
            case HotfixCodeRunMode.ILRuntime:
                ILRuntimeHelper.LoadHotfix(dllPath, isRegisterBindings);
                break;

            case HotfixCodeRunMode.Reflection:
            {
                var bytes  = File.ReadAllBytes(dllPath);
                var bytes2 = File.ReadAllBytes(dllPath + ".mdb");
                Assembly = Assembly.Load(bytes, bytes2);
                break;
            }

            case HotfixCodeRunMode.Editor:
                // 等分了asmdef 则去获取asmdef生成的程序集
                Assembly = Assembly.GetExecutingAssembly();
                break;
            }
        }
示例#11
0
    /// <summary>
    /// 分析dll生成
    /// </summary>
    /// <param name="platform"></param>
    /// <param name="dllpath"></param>
    static private void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin, string dllpath = "")
    {
        //默认参数
        if (platform == RuntimePlatform.Lumin)
        {
            platform = Application.platform;
        }

        if (dllpath == "")
        {
            dllpath = Application.streamingAssetsPath;
        }

        //路径
        dllpath = dllpath + "/" + BDApplication.GetPlatformPath(platform) + DLLPATH;
        //不参与自动绑定的
        List <Type> excludeTypes = new List <Type>(); //

        excludeTypes.AddRange(manualBindingTypes);
        excludeTypes.AddRange(preBindingTypes);
        //用新的分析热更dll调用引用来生成绑定代码
        var outputPath = "Assets/Code/BDFramework.Game/ILRuntime/Binding/Analysis";
        //游戏工程的Bind
        Action <bool> mainProjectIlrBindAction = null;
        var           type = BDFrameEditorLife.Types.FirstOrDefault((t) => t.FullName == "Game.ILRuntime.GameLogicCLRBinding");

        if (type != null)
        {
            var      method       = type.GetMethod("Bind", BindingFlags.Public | BindingFlags.Static);
            Delegate bindDelegate = Delegate.CreateDelegate(typeof(Action <bool>), null, method);
            mainProjectIlrBindAction = bindDelegate as Action <bool>;
        }
        else
        {
            Debug.LogError("Not find CLRBinding logic!!!");
        }
        //注册
        ILRuntimeHelper.LoadHotfix(dllpath, mainProjectIlrBindAction, false);
        BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, outputPath);
        ILRuntimeHelper.Close();


        /******************移除已经被绑定的部分****************/
        var analysisClrBinding = IPath.Combine(outputPath, "CLRBindings.cs");
        var manualPath         = "Assets/Code/BDFramework.Game/ILRuntime/Binding/Manual";
        var prebindingPath     = "Assets/Code/BDFramework.Game/ILRuntime/Binding/PreBinding";
        //手动绑定的所有文件
        var bindingFs = Directory.GetFiles(manualPath, "*.*").ToList();

        if (Directory.Exists(prebindingPath))
        {
            bindingFs.AddRange(Directory.GetFiles(prebindingPath, "*.*"));
        }

        for (int i = 0; i < bindingFs.Count; i++)
        {
            //删除被手动绑定的文件
            var f = IPath.Combine(outputPath, Path.GetFileName(bindingFs[i]));
            if (f != analysisClrBinding && File.Exists(f))
            {
                File.Delete(f);
            }

            bindingFs[i] = Path.GetFileNameWithoutExtension(bindingFs[i]);
        }

        var analysisContent = File.ReadAllLines(analysisClrBinding).ToList();

        //修改CLRbindding内容
        for (int i = analysisContent.Count - 1; i >= 0; i--)
        {
            var line = analysisContent[i];
            //移除line
            foreach (var mf in bindingFs)
            {
                if (line.Contains(mf + ".Register(app);"))
                {
                    analysisContent.RemoveAt(i);
                    Debug.Log("移除[已经绑定]:" + line);
                    break;
                }
            }
        }

        //写入
        File.WriteAllLines(analysisClrBinding, analysisContent);

        //Manual

        AssetDatabase.Refresh();
    }
    /// <summary>
    /// 分析dll生成
    /// </summary>
    /// <param name="platform"></param>
    /// <param name="dllpath"></param>
    static private void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin, string dllpath = "")
    {
        if (platform == RuntimePlatform.Lumin)
        {
            platform = Application.platform;
        }

        //默认读StreammingAssets下面path
        if (dllpath == "")
        {
            dllpath = Application.streamingAssetsPath + "/" + BApplication.GetPlatformPath(platform) + DLLPATH;
        }

        //不参与自动绑定的
        List <Type> excludeTypes = new List <Type>(); //

        excludeTypes.AddRange(manualBindingTypes);
        excludeTypes.AddRange(preBindingTypes);

        //用新的分析热更dll调用引用来生成绑定代码
        var outputPath = "Assets/Code/Game/ILRuntime/Binding/Analysis";

        ILRuntimeHelper.LoadHotfix(dllpath, false);
        BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, outputPath);
        ILRuntimeHelper.Close();


        /******************移除已经被绑定的部分****************/
        var analysisClrBinding = IPath.Combine(outputPath, "CLRBindings.cs");
        var manualPath         = "Assets/Code/Game/ILRuntime/Binding/Manual";
        var prebindingPath     = "Assets/Code/Game/ILRuntime/Binding/PreBinding";
        //手动绑定的所有文件
        var bindingFs = Directory.GetFiles(manualPath, "*.*").ToList();

        if (Directory.Exists(prebindingPath))
        {
            bindingFs.AddRange(Directory.GetFiles(prebindingPath, "*.*"));
        }

        for (int i = 0; i < bindingFs.Count; i++)
        {
            //删除被手动绑定的文件
            var f = IPath.Combine(outputPath, Path.GetFileName(bindingFs[i]));
            if (f != analysisClrBinding && File.Exists(f))
            {
                File.Delete(f);
            }

            bindingFs[i] = Path.GetFileNameWithoutExtension(bindingFs[i]);
        }

        var analysisContent = File.ReadAllLines(analysisClrBinding).ToList();

        //修改CLRbingding内容
        for (int i = analysisContent.Count - 1; i >= 0; i--)
        {
            var line = analysisContent[i];
            //移除line
            foreach (var mf in bindingFs)
            {
                if (line.Contains(mf + ".Register(app);"))
                {
                    analysisContent.RemoveAt(i);
                    Debug.Log("移除[已经绑定]:" + line);
                    break;
                }
            }
        }

        //写入
        File.WriteAllLines(analysisClrBinding, analysisContent);

        //Manual

        AssetDatabase.Refresh();
    }