Unity 编辑器扩展,获取目录下所有的预制件

先看演示效果

实现方案

1创建几个用于测试的cube

2,创建一个Editor脚本

3,编写脚本内容

附上源码

cs 复制代码
using UnityEditor;
using UnityEngine;

public class GetPrefeb : EditorWindow
{
    private string folderPath = "Assets/Resources"; // 指定预制体文件夹路径

    [MenuItem("Tool/Prefab Browser Window")]
    public static void ShowWindow()
    {
        GetWindow<GetPrefeb>("Prefab Browser");
    }

    private void OnGUI()
    {
        folderPath = EditorGUILayout.TextField("Folder Path: ", folderPath);

        if (GUILayout.Button("List Prefabs"))
        {
            ListPrefabsInFolder(folderPath);
        }
    }

    private void ListPrefabsInFolder(string folderPath)
    {
        string[] guids = AssetDatabase.FindAssets("t:Prefab", new string[] { folderPath });

        foreach (string guid in guids)
        {
            string assetPath = AssetDatabase.GUIDToAssetPath(guid);
            GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
            Debug.Log("Prefab" + assetPath);
            //这里处理你的逻辑
        }
    }
}

4.赶紧去试试吧,对获取到的预制件做自己的逻辑处理

相关推荐
水饺编程3 小时前
第5章,[Win32 章节] :贝塞尔样条曲线(一)
c语言·c++·windows·visual studio
辻弋2013 小时前
一键优化电源计划、游戏模式、独显强制、禁用后台录制——DeltaForceBooster专治三角洲行动卡顿掉帧,所有改动可一键还原
服务器·数据库·windows·游戏·电脑·php
言乐64 小时前
Python实现自动拉人脚本示例
开发语言·windows·python·django·pygame
深念Y5 小时前
OnlyOffice 打开来自 Windows/WPS 的 Office 文档时,出现排版错乱、文字空白、字体显示异常。
linux·windows·debian·onlyoffice·字体·wps·office
易点云徐源5 小时前
(已解决)adb devices 不显示设备,但 Windows 的 ADB Interface 正常:一次 WinUSB 与旧版 ADB 兼容性排查实战
windows·adb
奈斯先生Vector5 小时前
OpenScience 安装失败怎么办?Windows 环境、API 配置与本地服务排错指南
人工智能·windows·架构·开源·aigc·midjourney
AxureMost5 小时前
C盘清理工具 LightC
windows
csdn_aspnet6 小时前
C# 高效便利的处理数据
开发语言·windows·c#
淡海水6 小时前
03-02-线性-List-T-动态数组布局-扩容与操作成本
数据结构·windows·c#·list·编译·clr·机器码