首页 > 编程语言 > 详细

unity获取一个目录下的所有prefab路径

时间:2019-08-17 11:01:37      阅读:578      评论:0      收藏:0      [点我收藏+]

目录结构:

技术分享图片

获取Prefab下的所有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 directory)
    {
        if (string.IsNullOrEmpty(directory) || !directory.StartsWith("Assets"))
            throw new ArgumentException("folderPath");

        string[] subFolders = Directory.GetDirectories(directory);
        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]);
            }
        }
    }
}

 执行结果:

技术分享图片

  

unity获取一个目录下的所有prefab路径

原文:https://www.cnblogs.com/luguoshuai/p/11367153.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!