コード例 #1
0
    // 初始化热更程序
    private void InitHotfixProgram()
    {
        string typeName          = "Hotfix.Main";
        string startFunName      = "Start";
        string updateFunName     = "Update";
        string lateUpdateFunName = "LateUpdate";
        string uiLanguageFunName = "UILanguage";

        if (_isEnableILRuntime)
        {
            ILRRegister.Register(ILRDomain);
            _startFun           = new ILRStaticMethod(ILRDomain, typeName, startFunName, 0);
            _updateFun          = new ILRStaticMethod(ILRDomain, typeName, updateFunName, 0);
            _lateUpdateFun      = new ILRStaticMethod(ILRDomain, typeName, lateUpdateFunName, 0);
            _uiLanguageFun      = new ILRStaticMethod(ILRDomain, typeName, uiLanguageFunName, 1);
            HotfixAssemblyTypes = ILRDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToList();
        }
        else
        {
            Type type = _monoAssembly.GetType(typeName);
            _startFun           = new MonoStaticMethod(type, startFunName);
            _updateFun          = new MonoStaticMethod(type, updateFunName);
            _lateUpdateFun      = new MonoStaticMethod(type, lateUpdateFunName);
            _uiLanguageFun      = new MonoStaticMethod(type, uiLanguageFunName);
            HotfixAssemblyTypes = _monoAssembly.GetTypes().ToList <Type>();
        }
    }
コード例 #2
0
    static void GenerateCLRBindingByAnalysis()
    {
        // 先删除旧代码
        AssetDatabase.DeleteAsset(ILRDefine.StrMyBindingFolderPath);
        Directory.CreateDirectory(ILRDefine.StrMyBindingFolderPath);

        // 分析热更DLL来生成绑定代码
        ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain();
        string dllFilePath = $"{ILRDefine.StrMyAssemblyDir}/{ILRDefine.StrMyHotfixDLLFileName}.bytes";

        using (FileStream fs = new FileStream(dllFilePath, FileMode.Open, FileAccess.Read))
        {
            domain.LoadAssembly(fs);

            // Crossbind Adapter is needed to generate the correct binding code
            ILRRegister.Register(domain);

            // 生成所有绑定脚本
            ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, ILRDefine.StrMyBindingFolderPath);
        }

        // 刷新目录
        AssetDatabase.Refresh();
    }