Unity热更新HybridCLR+Addressables

编辑器打包到Addressables

using HybridCLR.Editor;
using HybridCLR.Editor.Commands;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.AddressableAssets.Settings.GroupSchemas;
using UnityEditor.AddressableAssets.Settings;
using UnityEditor.AddressableAssets;
using UnityEngine;

public static class HotUpdateHelper
{
   
    
    
    [MenuItem("HybridCLR/编译热更DLL,并且拷贝到Addressable")]
    public static void Copy2Addressable()
    {
   
    
    
        CompileDllCommand.CompileDllActiveBuildTarget();//官方提供脚本

        CopyAOTAssembliesToCache();
        CopyHotUpdateAssembliesToCache();

        //刷新资源
        AssetDatabase.Refresh();
    }


    public static void CopyAOTAssembliesToCache()
    {
   
    
    
        var target = EditorUserBuildSettings.activeBuildTarget;
        string aotAssembliesSrcDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
        string aotAssembliesDstDir = Application.dataPath + $"/HybridCLRBuildCache/AssetBundleOutput/StandaloneWindows64";

        foreach (var dll in SettingsUtil.AOTAssemblyNames)
        {
   
    
    
            string srcDllPath = $"{
     
      
      aotAssembliesSrcDir}/{
     
      
      dll}.dll";
            if (!File.Exists(srcDllPath))
            {
   
    
    
                Debug.LogError($"ab中添加AOT补充元数据dll:{
     
      
      srcDllPath} 时发生错误,文件不存在。裁剪后的AOT dll在BuildPlayer时才能生成,因此需要你先构建一次游戏App后再打包。");
                continue;
            }
            string dllBytesPath = $"{
     
      
      aotAssembliesDstDir}/{
     
      
      dll}.dll.bytes";
            File.Copy(srcDllPath, dllBytesPath, true);
            Debug.Log($"[CopyAOTAssembliesToStreamingAssets] copy AOT dll {
     
      
      srcDllPath} -> {
     
      
      dllBytesPath}");

            AddAssetToGroup(

猜你喜欢

转载自blog.csdn.net/u010197227/article/details/131518845
今日推荐