Unity 获取指定资源目录下的所有文件

时间:2022-06-17 12:33:18

获取 所有资源

[@MenuItem("Navy/Assets/Test")]
static void Test_Compoent(){
//OK
//这个不好用~
//Debug.Log(AssetDatabase.LoadAllAssetsAtPath("Assets/Models/21/21000001/21000001.prefab").Length);

//设置进度条
EditorUtility.DisplayProgressBar("设置AssetName名称", "正在设置AssetName名称中...", 0.50f);
EditorUtility.ClearProgressBar();

//路径
string fullPath = "Assets/Models/21/21000001" + "/";

//获取指定路径下面的所有资源文件
if (Directory.Exists(fullPath)){
DirectoryInfo direction = new DirectoryInfo(fullPath);
FileInfo[] files = direction.GetFiles("*",SearchOption.AllDirectories);

Debug.Log(files.Length);

for(int i=0;i<files.Length;i++){
if (files[i].Name.EndsWith(".meta")){
continue;
}
Debug.Log( "Name:" + files[i].Name );
//Debug.Log( "FullName:" + files[i].FullName );
//Debug.Log( "DirectoryName:" + files[i].DirectoryName );
}
}
}