HybridCLR Example

发布时间:2024年01月15日

https://gitee.com/weifen/hybrid-clrexample

模拟器测试:

hybridclr 热更真机测试

功能:

  • 一键构建PC,Android整包
  • 一键构建AssetBundle和dll热更
  • 一键本地热更测试
  • 热更构建时检查link和aot
  • sceneTest 测试场景加载
  • AssemblyCSharpHotUpdate 测试Assembly-CSharp作为热更dll加载

热更文件结构:

热更构建的时候会把生成的文件复制到StreamingAssets目录下
如果是构建热更会根据编译目标存放到 FileServer/{buildtarget}下
在这里插入图片描述

link.cs:

	// 整个程序集都不要裁剪
    private static readonly HashSet<string> assemblyAlls = new HashSet<string>
    {
        "mscorlib",
    };
    // 构建不同平台时会导致link增删,这里提供额外的补充
	private static readonly Dictionary<string, List<string>> fixedList = new Dictionary<string, List<string>>()
    {

    };

ScriptUpdate.cs:

根据提交记录和上次构建整包对比文件变化,aot出现改动时阻断

热更dll构建:

    private static void HotUpdateDll(BuildTarget buildTarget, bool developmentBuild = false, bool isGenerateAot = false)
    {
        if (!SettingsUtil.Enable)
        {
            Debug.Log("HybridCLR unenable");
            return;
        }

        InstallerController installer = new InstallerController();
        if (!installer.HasInstalledHybridCLR())
            installer.InstallDefaultHybridCLR();

        Il2CppDefGeneratorCommand.GenerateIl2CppDef();
        CompileDllCommand.CompileDll(buildTarget, developmentBuild);
        // 工程导出后已经裁剪的类不能通过AOT增加?
        // 暂时热更的时候去除AOT生成
        if(isGenerateAot)
        {
            StripAOTDllCommand.GenerateStripedAOTDlls(buildTarget);
            AOTReferenceGeneratorCommand.GenerateAOTGenericReference(buildTarget);
        }
        // 热更可能不能生成桥接函数,暂时先放着
        MethodBridgeGeneratorCommand.GenerateMethodBridge(buildTarget);
    }

构建步骤:

  1. 构建时先填充unity平台参数
  2. 根据编译参数填充宏
  3. 构建HybridCLR内容
  4. 构建AssetBundle,【可选】这里是为了用户第一次打开的时候不用再去下载,优化体验用
  5. 构建link
  6. 开始构建

预留了读取buildInfo.json文件方便使用命令行模式启动时读取编译参数,以下为编译参数

    private struct BuildInfo
    {
        public BuildTarget buildTarget;
        public BuildTargetGroup buildTargetGroup;
        public string localPathName;
        public UIOrientation orientation;
        public bool isRoationPortrait;
        public bool isRoationLeft;
        public bool isRoationRight;
        public bool isRoationDown;
        public bool isEnableHybridCLR;
        public string identifier;
        public bool isMono;
        public BuildType buildType;
        public bool buildWithDeepProfilingSupport;
        public bool ExportProject;
        public string bundleVersion;
        public int bundleVersionCode;
        public bool isAssetBundleIncrement;
    }

文章来源:https://blog.csdn.net/qq_17813937/article/details/135607301
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。