Unity编辑器扩展C#遍历文件夹以及子目录下的所有图片

下边是我自己写的编辑器扩展关于遍历文件夹下边以及子目录下的所有图片,仅提供参考

    [MenuItem("编辑器扩展关于图集/C#遍历文件夹以及子目录下的所有图片")]
    static void RefreshAllPicture()
    {
        string[] DebugAllImage = new string[] { };

         DebugAllImage=KnowAllPicture();

    }


    public static string[]  KnowAllPicture()
    {
        List<string> liststring = new List<string>();

        string myfolderPath = "PicTureFolder";
        string path = Path.Combine(Application.dataPath, myfolderPath);

        var images = Directory.GetFiles(path, ".", SearchOption.AllDirectories).Where(s => s.EndsWith(".png") || s.EndsWith(".jpg"));

        foreach(var i in images)
        {
            var str = i.Replace(Application.dataPath, "");
            var strpath = str.Replace("\\", "/");
            strpath = "Assets" + strpath;
            liststring.Add(strpath);
        }

        foreach(var item in liststring)
        {
            Debug.Log($"ITem:{item}\n");
        }

        return liststring.ToArray();
    }

版权声明:本文为charlsdm原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。