| | |
| | | private const string LaunchBackgroundFileName = "LoginBackground.jpg"; |
| | | private const string LaunchBackgroundVersionFileName = "version.txt"; |
| | | |
| | | // ==================================================================== |
| | | // 多语言随包资源:构建时开关与目录拼接 |
| | | // ==================================================================== |
| | | |
| | | private const string BUILD_LANGUAGE_PREF = "YooAsset_BuildLanguage"; |
| | | |
| | | /// <summary> |
| | | /// 当前构建使用的语言标识(与运行时 LocalResManager.Id/Language.Id 约定一致,如 "zh""en")。 |
| | | /// 仅影响构建输出目录,不影响实际打包的资源内容来源(若需按语言切换 Collector 源资源,需在调用本工具前另行处理)。 |
| | | /// </summary> |
| | | public static string BuildLanguage |
| | | { |
| | | get { return EditorPrefs.GetString(BUILD_LANGUAGE_PREF, string.Empty); } |
| | | set { EditorPrefs.SetString(BUILD_LANGUAGE_PREF, value); } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 实时从磁盘重新加载 VersionConfig.asset确定本次构建是否启用多语言随包目录。 |
| | | /// 不依赖 VersionConfig.config 静态缓存实例(可能在 PreBuild 重建资产后过期),确保每次构建都拿到磁盘上的最新开关值。 |
| | | /// 开关关闭或未配置语言时返回 null,保持原有无语言目录结构。 |
| | | /// </summary> |
| | | private static string ResolveActiveLanguage() |
| | | { |
| | | if (!IsLanguagePackageBuildEnabled()) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | string language = BuildLanguage; |
| | | return string.IsNullOrEmpty(language) ? null : language; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 实时从磁盘 VersionConfig.asset 判断是否启用多语言随包目录(与面板勾选同一个 asset)。 |
| | | /// APK/Export 消费侧根据此开关决定 StreamingAssets/yoo 下是平铺结构还是语言子目录结构。 |
| | | /// </summary> |
| | | public static bool IsLanguagePackageBuildEnabled() |
| | | { |
| | | var versionConfig = AssetDatabase.LoadAssetAtPath<VersionConfig>("Assets/Resources/VersionConfig.asset"); |
| | | return versionConfig != null && versionConfig.enableLanguagePackage; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 返回 yooRoot 下“包所在的容器目录”列表,用于兼容平铺与多语言两种结构。 |
| | | /// 依据**实际目录结构**判断(不靠语言开关,避免开关开启但资源仍是平铺时误判): |
| | | /// - yoo 根下直接含已知包目录(如 Builtin)→ 平铺结构,容器就是 yoo 根本身,返回 [yooRoot]。 |
| | | /// - 否则视 yoo 根下的子目录为语言目录,返回其中直接含包的子目录(yoo/zh, yoo/en...)。 |
| | | /// - 都识别不到包则兜底返回 [yooRoot]。 |
| | | /// APK/Export 流程中所有“遍历包目录”的操作(校验、裁剪删包)应基于此列表。 |
| | | /// </summary> |
| | | public static System.Collections.Generic.List<string> GetPackageContainerDirectories(string yooRoot) |
| | | { |
| | | var result = new System.Collections.Generic.List<string>(); |
| | | |
| | | // 开关关闭:永远走平铺结构,行为与改动前完全一致。 |
| | | if (!IsLanguagePackageBuildEnabled()) |
| | | { |
| | | result.Add(yooRoot); |
| | | return result; |
| | | } |
| | | |
| | | if (!System.IO.Directory.Exists(yooRoot)) |
| | | { |
| | | result.Add(yooRoot); |
| | | return result; |
| | | } |
| | | |
| | | // 平铺结构:包直接在 yoo 根下。 |
| | | if (DirectoryContainsAnyPackage(yooRoot)) |
| | | { |
| | | result.Add(yooRoot); |
| | | return result; |
| | | } |
| | | |
| | | // 语言结构:包在 yoo/{lang}/ 下。 |
| | | foreach (var sub in System.IO.Directory.GetDirectories(yooRoot)) |
| | | { |
| | | if (DirectoryContainsAnyPackage(sub)) |
| | | result.Add(sub); |
| | | } |
| | | |
| | | if (result.Count == 0) |
| | | result.Add(yooRoot); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 目录下是否直接包含任一已知 Package 子目录(用于区分平铺/语言目录)。 |
| | | /// </summary> |
| | | private static bool DirectoryContainsAnyPackage(string dir) |
| | | { |
| | | var validPackages = new System.Collections.Generic.HashSet<string>(GetAllPackageNames(), StringComparer.OrdinalIgnoreCase); |
| | | foreach (var d in System.IO.Directory.GetDirectories(dir)) |
| | | { |
| | | if (validPackages.Contains(System.IO.Path.GetFileName(d))) |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 在根目录后拼接语言子目录。language 为空时原样返回,与运行时 GetLanguagePackageRoot 约定保持一致。 |
| | | /// </summary> |
| | | private static string ApplyLanguageSubfolder(string root, string language) |
| | | { |
| | | return string.IsNullOrEmpty(language) ? root : System.IO.Path.Combine(root, language); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// AOT 元数据 DLL 列表 —— 所有平台通用部分 |
| | | /// (与 AOTGenericReferences.PatchedAOTAssemblyList 保持一致) |
| | |
| | | System.IO.Directory.CreateDirectory(destFullPath); |
| | | |
| | | int copiedCount = 0; |
| | | foreach (var packageName in GetAllPackageNames()) |
| | | // 语言模式下包在 yoo/{lang}/{pkg},需按容器目录遍历并保留语言子目录结构;平铺模式容器即 yoo 根。 |
| | | foreach (var container in GetPackageContainerDirectories(sourceFullPath)) |
| | | { |
| | | string sourcePackageDir = System.IO.Path.Combine(sourceFullPath, packageName); |
| | | if (!System.IO.Directory.Exists(sourcePackageDir)) |
| | | bool isRoot = NormalizeFullPath(container) == sourceFullPath; |
| | | string langSub = isRoot ? null : System.IO.Path.GetFileName(container); |
| | | foreach (var packageName in GetAllPackageNames()) |
| | | { |
| | | continue; |
| | | } |
| | | string sourcePackageDir = System.IO.Path.Combine(container, packageName); |
| | | if (!System.IO.Directory.Exists(sourcePackageDir)) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | copiedCount += CopyDirectoryFiles(sourcePackageDir, System.IO.Path.Combine(destFullPath, packageName)); |
| | | string destPackageDir = string.IsNullOrEmpty(langSub) |
| | | ? System.IO.Path.Combine(destFullPath, packageName) |
| | | : System.IO.Path.Combine(destFullPath, langSub, packageName); |
| | | copiedCount += CopyDirectoryFiles(sourcePackageDir, destPackageDir); |
| | | } |
| | | } |
| | | |
| | | bool configCopied = false; |
| | |
| | | } |
| | | |
| | | bool success = true; |
| | | string streamingYooRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); |
| | | string language = ResolveActiveLanguage(); |
| | | string streamingYooRoot = ApplyLanguageSubfolder(AssetBundleBuilderHelper.GetStreamingAssetsRoot(), language); |
| | | if (!CopyPackageBuildOutputToYooDirectory(packageName, streamingYooRoot, version, "StreamingAssets")) |
| | | { |
| | | success = false; |
| | |
| | | |
| | | if (!string.IsNullOrWhiteSpace(outputPath)) |
| | | { |
| | | string destYooRoot = ResolveYooOutputDirectory(outputPath); |
| | | string destYooRoot = ApplyLanguageSubfolder(ResolveYooOutputDirectory(outputPath), language); |
| | | string streamingFullPath = NormalizeFullPath(streamingYooRoot); |
| | | string destFullPath = NormalizeFullPath(destYooRoot); |
| | | if (string.Equals(streamingFullPath, destFullPath, StringComparison.OrdinalIgnoreCase)) |
| | |
| | | } |
| | | |
| | | public static void ClearStreamingAssetsYooDirectory() |
| | | { |
| | | string rootYoo = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); |
| | | string language = ResolveActiveLanguage(); |
| | | |
| | | if (string.IsNullOrEmpty(language)) |
| | | { |
| | | // 平铺模式:清整个 yoo 根。 |
| | | if (System.IO.Directory.Exists(rootYoo)) |
| | | System.IO.Directory.Delete(rootYoo, true); |
| | | System.IO.Directory.CreateDirectory(rootYoo); |
| | | return; |
| | | } |
| | | |
| | | // 语言模式:清当前语言目录(重新 build),并清理 yoo 根下残留的平铺包目录(从平铺模式切换过来的旧产物), |
| | | // 保留其他语言目录(不破坏“随包两份语言”)。 |
| | | string langYoo = System.IO.Path.Combine(rootYoo, language); |
| | | if (System.IO.Directory.Exists(langYoo)) |
| | | System.IO.Directory.Delete(langYoo, true); |
| | | System.IO.Directory.CreateDirectory(langYoo); |
| | | |
| | | if (System.IO.Directory.Exists(rootYoo)) |
| | | { |
| | | var validPackages = new System.Collections.Generic.HashSet<string>(GetAllPackageNames(), StringComparer.OrdinalIgnoreCase); |
| | | foreach (var dir in System.IO.Directory.GetDirectories(rootYoo)) |
| | | { |
| | | string name = System.IO.Path.GetFileName(dir); |
| | | if (!validPackages.Contains(name)) |
| | | continue; |
| | | |
| | | System.IO.Directory.Delete(dir, true); |
| | | string metaPath = dir + ".meta"; |
| | | if (System.IO.File.Exists(metaPath)) |
| | | System.IO.File.Delete(metaPath); |
| | | Debug.Log($"[YooAssetBuildTool] 已清理旧平铺包目录(残留): {name}"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清空整个 StreamingAssets/yoo 根目录(含所有语言子目录)。 |
| | | /// 用于 NullAsset(小包)打包:不随包携带任何 yoo 资源,全部从 CDN 按需下载。 |
| | | /// 与 ClearStreamingAssetsYooDirectory(仅清当前语言子目录,build 前用)区分。 |
| | | /// </summary> |
| | | public static void ClearAllStreamingAssetsYoo() |
| | | { |
| | | string yooRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); |
| | | if (System.IO.Directory.Exists(yooRoot)) |
| | |
| | | string buildRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); |
| | | string platform = EditorUserBuildSettings.activeBuildTarget.ToString(); |
| | | string srcRoot = $"{buildRoot}/{platform}"; |
| | | string destRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); |
| | | string destRoot = ApplyLanguageSubfolder(AssetBundleBuilderHelper.GetStreamingAssetsRoot(), ResolveActiveLanguage()); |
| | | |
| | | if (!System.IO.Directory.Exists(srcRoot)) |
| | | { |
| | |
| | | public static void WriteBuildinPackageList() |
| | | { |
| | | string yooRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); |
| | | // 多语言开启时,包在语言子目录下(yoo/{lang}/{pkg}),从第一个容器目录扫包名即可(各语言包列表一致)。 |
| | | var containers = GetPackageContainerDirectories(yooRoot); |
| | | string scanDir = containers.Count > 0 ? containers[0] : yooRoot; |
| | | var existing = new System.Collections.Generic.List<string>(); |
| | | var validPackages = new System.Collections.Generic.HashSet<string>(GetAllPackageNames(), StringComparer.OrdinalIgnoreCase); |
| | | if (System.IO.Directory.Exists(yooRoot)) |
| | | if (System.IO.Directory.Exists(scanDir)) |
| | | { |
| | | foreach (var dir in System.IO.Directory.GetDirectories(yooRoot)) |
| | | foreach (var dir in System.IO.Directory.GetDirectories(scanDir)) |
| | | { |
| | | var dirName = System.IO.Path.GetFileName(dir); |
| | | if (validPackages.Contains(dirName)) |
| | |
| | | { |
| | | try |
| | | { |
| | | Debug.Log($"[YooAssetBuildTool] 开始打包 Package: {packageName}, 版本: {version}"); |
| | | string language = ResolveActiveLanguage(); |
| | | Debug.Log($"[YooAssetBuildTool] 开始打包 Package: {packageName}, 版本: {version}" + |
| | | (string.IsNullOrEmpty(language) ? string.Empty : $", 语言: {language}")); |
| | | |
| | | var buildParameters = new BuiltinBuildParameters(); |
| | | buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); |
| | | buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); |
| | | // 多语言随包资源:开关开启且配置了语言时,YooAsset 内部拷贝直接写入 yoo/{language}/{packageName}, |
| | | // 与运行时 YooAssetService/YooAssetInitializer 的 GetLanguagePackageRoot 探测路径保持一致。 |
| | | buildParameters.BuildinFileRoot = ApplyLanguageSubfolder(AssetBundleBuilderHelper.GetStreamingAssetsRoot(), language); |
| | | buildParameters.BuildPipeline = EBuildPipeline.BuiltinBuildPipeline.ToString(); |
| | | buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle; |
| | | buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; |