unity c# 判断资源大小

发布时间:2024年01月17日

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("无效的路径!");

}

}

}

文章来源:https://blog.csdn.net/qq_21743659/article/details/135623122
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。