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.赶紧去试试吧,对获取到的预制件做自己的逻辑处理

相关推荐
SeanQhl2 小时前
中文 Windows 上跑 Python 定时任务——编码、路径、控制台三个坑
windows·python·编码·效率工具·定时任务
淡海水3 小时前
01-03-认知篇-基础-Excel配置工作流痛点深度分析
unity·架构·excel·游戏开发·luban
Vex2une6 小时前
系统出问题不想重装?系统还原点创建与重置此电脑完整指南
windows·系统还原点·重置此电脑·系统还原怎么用·创建还原点·保留文件重置·系统保护开启
保卫大狮兄1 天前
2026中小制造企业轻量化ERP选型观察:产供销协同路线、上线周期与ROI分析
windows·microsoft·erp·生产管理
陈工大模型1 天前
MacOS 跨平台压缩包处理:从编码痛点到工程化落地的完整方案
windows·macos·缓存·电脑·策略模式·c盘清理
凌镜icecraft2 天前
我改文件扩展名的时候那个警告弹窗再也不会弹出来了
windows·c#·wpf·explorer
the3clipse2 天前
Windows 11 26H2 AI 功能使用指南:回顾、单击以执行与实时字幕
人工智能·windows·copilot+ pc·recall 回顾·单击以执行·实时字幕翻译·windows studio
the3clipse2 天前
Windows 11 26H2 账户登录与 Windows Hello 指南:并行验证、增强登录安全与无密码设置
windows·无密码登录·windows hello·增强登录安全性ess·pin与密码区别·动态锁·win11 26h2
承渊政道2 天前
Toonflow AI短剧教程:Windows部署、批量生成与角色一致性
人工智能·windows·cpolar·ai短剧·toonflow
柳鲲鹏4 天前
编译Windows版本的zlib
windows