HybridCLR Example

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;
    }

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小鱼游戏开发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值