Initial commit: Client Doc docs Server Tools
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
|
||||
using HybridCLR.Editor.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor
|
||||
{
|
||||
public static class BuildAssetsCommand
|
||||
{
|
||||
public static string HybridCLRBuildCacheDir => Application.dataPath + "/HybridCLRBuildCache";
|
||||
|
||||
public static string AssetBundleOutputDir => $"{HybridCLRBuildCacheDir}/AssetBundleOutput";
|
||||
|
||||
public static string AssetBundleSourceDataTempDir => $"{HybridCLRBuildCacheDir}/AssetBundleSourceData";
|
||||
|
||||
|
||||
public static string GetAssetBundleOutputDirByTarget(BuildTarget target)
|
||||
{
|
||||
return $"{AssetBundleOutputDir}/{target}";
|
||||
}
|
||||
|
||||
public static string GetAssetBundleTempDirByTarget(BuildTarget target)
|
||||
{
|
||||
return $"{AssetBundleSourceDataTempDir}/{target}";
|
||||
}
|
||||
|
||||
public static string ToRelativeAssetPath(string s)
|
||||
{
|
||||
return s.Substring(s.IndexOf("Assets/"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将HotFix.dll和HotUpdatePrefab.prefab打入common包.
|
||||
/// 将HotUpdateScene.unity打入scene包.
|
||||
/// </summary>
|
||||
/// <param name="tempDir"></param>
|
||||
/// <param name="outputDir"></param>
|
||||
/// <param name="target"></param>
|
||||
private static void BuildAssetBundles(string tempDir, string outputDir, BuildTarget target)
|
||||
{
|
||||
Directory.CreateDirectory(tempDir);
|
||||
Directory.CreateDirectory(outputDir);
|
||||
|
||||
List<AssetBundleBuild> abs = new List<AssetBundleBuild>();
|
||||
|
||||
{
|
||||
var prefabAssets = new List<string>();
|
||||
string testPrefab = $"{Application.dataPath}/Prefabs/HotUpdatePrefab.prefab";
|
||||
prefabAssets.Add(testPrefab);
|
||||
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
||||
abs.Add(new AssetBundleBuild
|
||||
{
|
||||
assetBundleName = "prefabs",
|
||||
assetNames = prefabAssets.Select(s => ToRelativeAssetPath(s)).ToArray(),
|
||||
});
|
||||
}
|
||||
|
||||
BuildPipeline.BuildAssetBundles(outputDir, abs.ToArray(), BuildAssetBundleOptions.None, target);
|
||||
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
||||
}
|
||||
|
||||
public static void BuildAssetBundleByTarget(BuildTarget target)
|
||||
{
|
||||
BuildAssetBundles(GetAssetBundleTempDirByTarget(target), GetAssetBundleOutputDirByTarget(target), target);
|
||||
}
|
||||
|
||||
[MenuItem("HybridCLR/Build/BuildAssetsAndCopyToStreamingAssets")]
|
||||
public static void BuildAndCopyABAOTHotUpdateDlls()
|
||||
{
|
||||
BuildAssetBundleByTarget(EditorUserBuildSettings.activeBuildTarget);
|
||||
CopyAssetBundlesToStreamingAssets();
|
||||
CompileDllCommand.CompileDllActiveBuildTarget();
|
||||
CopyAOTAssembliesToStreamingAssets();
|
||||
CopyHotUpdateAssembliesToStreamingAssets();
|
||||
}
|
||||
|
||||
//[MenuItem("HybridCLR/Build/Copy_AB_AOT_HotUpdateDlls")]
|
||||
public static void Copy_AB_AOT_HotUpdateDlls()
|
||||
{
|
||||
CopyAOTAssembliesToStreamingAssets();
|
||||
CopyHotUpdateAssembliesToStreamingAssets();
|
||||
CopyAssetBundlesToStreamingAssets();
|
||||
}
|
||||
|
||||
|
||||
//[MenuItem("HybridCLR/Build/BuildAssetbundle")]
|
||||
public static void BuildSceneAssetBundleActiveBuildTargetExcludeAOT()
|
||||
{
|
||||
BuildAssetBundleByTarget(EditorUserBuildSettings.activeBuildTarget);
|
||||
}
|
||||
|
||||
public static void CopyAOTAssembliesToStreamingAssets()
|
||||
{
|
||||
var target = EditorUserBuildSettings.activeBuildTarget;
|
||||
string aotAssembliesSrcDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
|
||||
string aotAssembliesDstDir = Application.streamingAssetsPath+"/xaot";//改为aot目录
|
||||
if (!Directory.Exists(aotAssembliesDstDir))
|
||||
Directory.CreateDirectory(aotAssembliesDstDir);
|
||||
foreach (var dll in Packager.AOTMetaAssemblyNames)
|
||||
{
|
||||
string srcDllPath = $"{aotAssembliesSrcDir}/{dll}";
|
||||
if (!File.Exists(srcDllPath))
|
||||
{
|
||||
Debug.LogError($"ab中添加AOT补充元数据dll:{srcDllPath} 时发生错误,文件不存在。裁剪后的AOT dll在BuildPlayer时才能生成,因此需要你先构建一次游戏App后再打包。");
|
||||
continue;
|
||||
}
|
||||
string dllBytesPath = $"{aotAssembliesDstDir}/{dll}";
|
||||
File.Copy(srcDllPath, dllBytesPath, true);
|
||||
Debug.Log($"[CopyAOTAssembliesToStreamingAssets] copy AOT dll {srcDllPath} -> {dllBytesPath}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyHotUpdateAssembliesToStreamingAssets()
|
||||
{
|
||||
var target = EditorUserBuildSettings.activeBuildTarget;
|
||||
|
||||
string hotfixDllSrcDir = SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target);
|
||||
string hotfixAssembliesDstDir = Application.streamingAssetsPath+"/xhotfix";//改为hotfix目录
|
||||
if (!Directory.Exists(hotfixAssembliesDstDir))
|
||||
Directory.CreateDirectory(hotfixAssembliesDstDir);
|
||||
foreach (var dll in SettingsUtil.HotUpdateAssemblyFilesExcludePreserved)
|
||||
{
|
||||
string dllPath = $"{hotfixDllSrcDir}/{dll}";
|
||||
string dllBytesPath = $"{hotfixAssembliesDstDir}/{dll}";
|
||||
File.Copy(dllPath, dllBytesPath, true);
|
||||
Debug.Log($"[CopyHotUpdateAssembliesToStreamingAssets] copy hotfix dll {dllPath} -> {dllBytesPath}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyAssetBundlesToStreamingAssets()
|
||||
{
|
||||
var target = EditorUserBuildSettings.activeBuildTarget;
|
||||
string streamingAssetPathDst = Application.streamingAssetsPath;
|
||||
Directory.CreateDirectory(streamingAssetPathDst);
|
||||
string outputDir = GetAssetBundleOutputDirByTarget(target);
|
||||
var abs = new string[] { "prefabs" };
|
||||
foreach (var ab in abs)
|
||||
{
|
||||
string srcAb = ToRelativeAssetPath($"{outputDir}/{ab}");
|
||||
string dstAb = ToRelativeAssetPath($"{streamingAssetPathDst}/{ab}");
|
||||
Debug.Log($"[CopyAssetBundlesToStreamingAssets] copy assetbundle {srcAb} -> {dstAb}");
|
||||
AssetDatabase.CopyAsset( srcAb, dstAb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user