using UnityEngine;
public class ResourceSizeChecker : MonoBehaviour {
void Start() {
// 获取指定路径下的文件或者目录的大小(单位为字节)
long size = GetFileOrDirectorySize("Assets/YourResourcePath");
Debug.Log("资源大小为:" + size);
}
private static long GetFileOrDirectorySize(string path) {
if (System.IO.File.Exists(path)) {
return new System.IO.FileInfo(path).Length;
} else if (System.IO.Directory.Exists(path)) {
long totalSize = 0;
foreach (var file in System.IO.Directory.GetFiles(path)) {
totalSize += new System.IO.FileInfo(file).Length;
}
foreach (var directory in System.IO.Directory.GetDirectories(path)) {
totalSize += GetFileOrDirectorySize(directory);
}
return totalSize;
} else {
throw new System.Exception("无效的路径!");
}
}
}