NLDClient-yudde/ProjectNLD/Assets/Editor/LevelCheckers/LevelFileSizeChecker.cs

44 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
using PhxhSDK.Editor.FileChecker.Data;
namespace PhxhSDK.Editor.FileChecker
{
/// <summary>
/// 关卡文件大小检查器
/// 检查关卡json文件的大小是否合理
/// </summary>
public class LevelFileSizeChecker : BaseLevelChecker
{
public override string CheckerName => "关卡文件大小检查";
public override string RecommendedHandling => "请检查关卡文件是否包含过多数据,考虑优化关卡设计";
public override CheckerTabType belongTab => CheckerTabType.Level;
public override bool HasAutoProgress => false;
// 最大文件大小限制(字节)
private const long MAX_FILE_SIZE = 100 * 1024; // 100KB
public override string CheckLevel(string filePath, TextAsset textAsset)
{
if (textAsset == null)
{
return "文件加载失败";
}
// 获取文件大小
long fileSize = textAsset.bytes.Length;
if (fileSize > MAX_FILE_SIZE)
{
float sizeInKB = fileSize / 1024f;
return $"文件过大:{sizeInKB:F1}KB超过限制{MAX_FILE_SIZE / 1024}KB";
}
// 文件大小合理
return null;
}
}
}