using Framework; using UnityEditor; using UnityEngine; using cfg.LevelCfg; using Sirenix.Utilities; using Sirenix.OdinInspector; using Sirenix.Utilities.Editor; using Level = cfg.LevelCfg.Level; using System.Collections.Generic; using Sirenix.OdinInspector.Editor; public class LevelValidatorWindow : OdinEditorWindow { [MenuItem("Tools/关卡地图资源检查")] public static void ShowWindow() { curWindow = GetWindow(); curWindow.position = GUIHelper.GetEditorWindowRect().AlignCenter(300, 250); curWindow.titleContent = new GUIContent("关卡资源检查"); curWindow.LoadLevelCfg(); } private static LevelValidatorWindow curWindow; private Level levelCfg; private void LoadLevelCfg() { levelCfg = EditorTableManager.instance.tables.Level; } // 映射不同的检查类型 private readonly Dictionary> checkDictionary = new() { { "CheckAll", (levelDataPath, mapDataPath, dataLevel) => new LevelValidatorBase[] { new CheckCaptureData(levelDataPath, mapDataPath), new CheckFlagData(levelDataPath, mapDataPath), new CheckProtectData(levelDataPath, mapDataPath), new CheckLevelRegionData(levelDataPath, mapDataPath), new CheckScenePostProcess(dataLevel), new CheckLevelCondition(levelDataPath, mapDataPath), new CheckLevelStarTarget(levelDataPath, mapDataPath), new CheckLevelScoreTarget(levelDataPath, mapDataPath) } }, { "CheckFlag", (levelDataPath, mapDataPath, dataLevel) => new LevelValidatorBase[] { new CheckFlagData(levelDataPath, mapDataPath) } }, { "CheckCapture", (levelDataPath, mapDataPath, dataLevel) => new LevelValidatorBase[] { new CheckCaptureData(levelDataPath, mapDataPath) } }, { "CheckProtect", (levelDataPath, mapDataPath, dataLevel) => new LevelValidatorBase[] { new CheckProtectData(levelDataPath, mapDataPath), } }, { "CheckRegion", (levelDataPath, mapDataPath, dataLevel) => new LevelValidatorBase[] { new CheckLevelRegionData(levelDataPath, mapDataPath), } }, { "CheckScenePostProcess", (levelDataPath, mapDataPath, dataLevel) => new LevelValidatorBase[] { new CheckScenePostProcess(dataLevel), } }, { "CheckStage", (levelDataPath, mapDataPath, dataLevel) => new LevelValidatorBase[] { new CheckLevelCondition(levelDataPath, mapDataPath), new CheckLevelStarTarget(levelDataPath, mapDataPath), new CheckLevelScoreTarget(levelDataPath, mapDataPath) } }, }; private void RunCheck(string checkType) { var levelValidator = new Dictionary(); foreach (var dataLevel in levelCfg.DataMap) { var levelDataPath = dataLevel.Value.LevelData; var mapDataPath = dataLevel.Value.MapData; if (!levelValidator.ContainsKey(dataLevel.Key)) { levelValidator.Add(dataLevel.Key, checkDictionary[checkType](levelDataPath, mapDataPath, dataLevel.Value)); } } GetTipsMessage(levelValidator); } private void GetTipsMessage(Dictionary levelValidatorMap) { foreach (var levelValidatorData in levelValidatorMap) { var levelErrorTitle = $"关卡ID:{levelValidatorData.Key}"; var errorLevelMessage = ""; var levelWarningTitle = $"关卡ID:{levelValidatorData.Key}"; var warningLevelMessage = ""; foreach (var validator in levelValidatorData.Value) { if (validator.ErrorData) { AppendWithNewLine(ref errorLevelMessage, validator.ErrorMessage); break; } if (!validator.CheckData()) { AppendWithNewLine(ref errorLevelMessage, validator.ErrorMessage); AppendWithNewLine(ref warningLevelMessage, validator.WarningMessage); } } if (!string.IsNullOrEmpty(errorLevelMessage)) { AppendWithNewLine(ref levelErrorTitle, errorLevelMessage); DebugUtil.LogError(levelErrorTitle); } if (!string.IsNullOrEmpty(warningLevelMessage)) { AppendWithNewLine(ref levelWarningTitle, warningLevelMessage); DebugUtil.LogWarning(levelWarningTitle); } } } private void AppendWithNewLine(ref string original, string newString) { if (!string.IsNullOrEmpty(original)) { original += "\n"; } original += newString; } [VerticalGroup("Check"), PropertySpace(10)] [Button("检查所有关卡配置")] private void CheckAllLevelInfo() { RunCheck("CheckAll"); } [VerticalGroup("Check"), PropertySpace(10)] [Button("检查扛旗相关")] private void CheckLevelFlag() { RunCheck("CheckFlag"); } [VerticalGroup("Check"), PropertySpace(10)] [Button("检查占领相关")] private void CheckLevelCapture() { RunCheck("CheckCapture"); } [VerticalGroup("Check"), PropertySpace(10)] [Button("检查护送相关")] private void CheckLevelProtect() { RunCheck("CheckProtect"); } [VerticalGroup("Check"), PropertySpace(10)] [Button("检查地区相关")] private void CheckLevelRegion() { RunCheck("CheckRegion"); } [VerticalGroup("Check"), PropertySpace(10)] [Button("检查后处理场景相关")] private void CheckLevelScenePostProcess() { RunCheck("CheckScenePostProcess"); } [VerticalGroup("Check"), PropertySpace(10)] [Button("检查关卡条件相关")] private void CheckLevelStage() { RunCheck("CheckStage"); } }