Files
Studio/Assets/Editor/WI/ResourcesFileSizeExporter.cs

45 lines
1.4 KiB
C#
Raw Normal View History

using UnityEditor;
using UnityEngine;
using System.IO;
using System.Collections.Generic;
using Newtonsoft.Json;
using Studio.Manage;
public class ResourcesFileSizeExporter
{
[MenuItem("Tools/Export Resources File Sizes to JSON")]
public static void ExportFileSizes()
{
string resourcesPath = Application.dataPath + "/Resources";
var sampleAssetPaths = Application.dataPath + "/Resources/Sample";
var fileSizeListWrapper = new FileSizeListWrapper();
if (!Directory.Exists(sampleAssetPaths))
{
return;
}
Dictionary<string, long> fileSizes = new Dictionary<string, long>();
string[] files = Directory.GetFiles(sampleAssetPaths, "*.prefab", SearchOption.AllDirectories);
foreach (string filePath in files)
{
var fileEntry = new FileSizeEntry();
long fileByteSize = new FileInfo(filePath).Length;
string fileName = Path.GetFileNameWithoutExtension(filePath);
fileEntry.name = fileName;
fileEntry.size = fileByteSize;
fileSizeListWrapper.files.Add(fileEntry);
}
string json = JsonConvert.SerializeObject(fileSizeListWrapper);
string outputPath = Path.Combine(resourcesPath, "FileSizes.json");
File.WriteAllText(outputPath, json);
Debug.Log($"<22><><EFBFBD><EFBFBD> <20≯<EFBFBD><><C5A9> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ǿ<EFBFBD><C7BE><EFBFBD><EFBFBD>ϴ<EFBFBD>: {outputPath}");
AssetDatabase.Refresh();
}
}