多轮审查和修复
This commit is contained in:
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor.AddressableAssets;
|
||||
@@ -16,6 +18,30 @@ namespace BaseGames.Editor
|
||||
/// 是否与 Addressable 分组中实际存在的地址同步(架构 13_AssetPoolModule §10)。
|
||||
///
|
||||
/// 菜单:BaseGames → Tools → Validate Address Keys
|
||||
/// Build 回调顺序 = 0(在 SOValidationRunner callbackOrder = 1 之前执行)
|
||||
/// </summary>
|
||||
public class AddressKeyValidatorBuildHook : IPreprocessBuildWithReport
|
||||
{
|
||||
public int callbackOrder => 0;
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
var results = AddressKeyValidator.RunValidation();
|
||||
int missing = results.Count(r => !r.ExistsInAddressables);
|
||||
if (missing > 0)
|
||||
{
|
||||
var orphans = results
|
||||
.Where(r => !r.ExistsInAddressables)
|
||||
.Select(r => $"AddressKeys.{r.FieldName} = \"{r.Value}\"");
|
||||
throw new BuildFailedException(
|
||||
$"[AddressKeyValidator] {missing} 个孤儿 AddressKey,构建中止:\n"
|
||||
+ string.Join("\n", orphans));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Editor 静态工具类:验证逻辑和 MenuItem 入口。
|
||||
/// </summary>
|
||||
public static class AddressKeyValidator
|
||||
{
|
||||
@@ -91,7 +117,8 @@ namespace BaseGames.Editor
|
||||
if (missing == 0)
|
||||
Debug.Log($"[AddressKeyValidator] ✓ 所有 {results.Count} 个 AddressKeys 常量均在 Addressable 分组中存在。");
|
||||
else
|
||||
Debug.LogWarning($"[AddressKeyValidator] 共 {results.Count} 个常量,发现 {missing} 个孤儿 Key,请检查 Addressable 分组配置。");
|
||||
Debug.LogWarning($"[AddressKeyValidator] 共 {results.Count} 个常量,发现 {missing} 个孤儿 Key。" +
|
||||
$"尚未创建的 Prefab/Scene 资产请在创建后添加至 Addressables 分组。");
|
||||
}
|
||||
|
||||
// ── 结果结构 ──────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user