Get all prefab unity under a directory path

Directory Structure:

Get all prefab under Prefab

using System;
using System.IO;
using UnityEditor;
using UnityEngine;

public class Test
{
    [MenuItem("BuildTool/Lugs")]
    static void LugsTest()
    {
        string path = "Assets/UI/Prefab";
        GetAllPrefabs(path);
    }

    static void GetAllPrefabs(string diecrory)
    {
        if (string.IsNullOrEmpty(diecrory) || !diecrory.StartsWith("Assets"))
            throw new ArgumentException("folderPath");

        string[] subFolders = Directory.GetDirectories(diecrory);
        string[] guids = null;
        string[] assetPaths = null;
        int i = 0, iMax = 0;
        foreach (var folder in subFolders)
        {
            guids = AssetDatabase.FindAssets("t:Prefab", new string[] { folder });
            assetPaths = new string[guids.Length];
            for (i = 0, iMax = assetPaths.Length; i < iMax; ++i)
            {
                assetPaths[i] = AssetDatabase.GUIDToAssetPath(guids[i]);
                Debug.Log(assetPaths[i]);
            }
        }
    }
}

  

Guess you like

Origin www.cnblogs.com/luguoshuai/p/11367153.html