您可以使用Unity的AssetDatabase类和AssetDatabase.FindAssets方法来获取某个文件夹下所有文件的GUID,然后使用AssetDatabase.GUIDToAssetPath方法将GUID转换为文件路径。

下面是一个示例代码,获取Assets/MyFolder下所有文件的路径:

using UnityEditor;
using UnityEngine;

public class GetAllFilesInFolder : EditorWindow
{
    [MenuItem("Window/Get All Files In Folder")]
    public static void ShowWindow()
    {
        EditorWindow.GetWindow(typeof(GetAllFilesInFolder));
    }

    private void OnGUI()
    {
        if (GUILayout.Button("Get All Files"))
        {
            string folderPath = "Assets/MyFolder";
            string[] guids = AssetDatabase.FindAssets("", new[] { folderPath });
            foreach (string guid in guids)
            {
                string assetPath = AssetDatabase.GUIDToAssetPath(guid);
                Debug.Log(assetPath);
            }
        }
    }
}

在Unity编辑器中选择Window -> Get All Files In Folder,然后点击Get All Files按钮,即可在Console窗口中查看所有文件的路径

unity editor获取某文件夹下所有文件

原文地址: https://www.cveoy.top/t/topic/eExV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录