60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
using System.Collections.Generic;
|
||
using System.IO;
|
||
using UnityEditor;
|
||
using UnityEngine;
|
||
using PhxhSDK.Editor.FileChecker.Data;
|
||
|
||
namespace PhxhSDK.Editor.FileChecker
|
||
{
|
||
/// <summary>
|
||
/// 关卡json文件检查器基类
|
||
/// </summary>
|
||
public abstract class BaseLevelChecker : BaseFileChecker<TextAsset>
|
||
{
|
||
public override List<string> fileExtensions => new() { "json" };
|
||
|
||
public override string CheckerDescription => "关卡JSON文件检查器";
|
||
|
||
// 这些属性需要在子类中实现
|
||
public abstract override string CheckerName { get; }
|
||
public abstract override string RecommendedHandling { get; }
|
||
public abstract override CheckerTabType belongTab { get; }
|
||
|
||
protected override void _OnCheckFile(string filePath, TextAsset loadObject)
|
||
{
|
||
// 检查文件路径是否包含关卡相关目录
|
||
if (!IsLevelFile(filePath))
|
||
{
|
||
return;
|
||
}
|
||
|
||
var result = CheckLevel(filePath, loadObject);
|
||
if (result != null)
|
||
{
|
||
_PushMsg(result);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检查是否为关卡文件
|
||
/// </summary>
|
||
/// <param name="filePath">文件路径</param>
|
||
/// <returns>是否为关卡文件</returns>
|
||
protected virtual bool IsLevelFile(string filePath)
|
||
{
|
||
string normalizedPath = filePath.Replace("\\", "/");
|
||
return normalizedPath.Contains("/Levels/") ||
|
||
normalizedPath.Contains("/LegionLevels/") ||
|
||
(normalizedPath.Contains("/Config/") && Path.GetFileName(filePath).StartsWith("LevelData_"));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检查单个关卡文件
|
||
/// </summary>
|
||
/// <param name="filePath">文件路径</param>
|
||
/// <param name="textAsset">文本资源</param>
|
||
/// <returns>如果检查失败,返回失败信息;如果检查通过,返回null</returns>
|
||
public abstract string CheckLevel(string filePath, TextAsset textAsset);
|
||
}
|
||
}
|