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

相关推荐
scott.cgi21 分钟前
Unity直接编译Java文件作为插件,导致失败的两个打包设置
java·unity·unity调用java·unity的java文件·unity的android插件·unity调用android·unity加载java代码
vortex56 小时前
PowerShell 的命令补全方案: PSReadLine + PSCompletions + argc + Carapace
windows·powershell
Ujimatsu7 小时前
虚拟机安装Ubuntu 26.04.x服务器版(命令行版)(2026.5)
linux·windows·ubuntu
小墨宝9 小时前
vscode自带内网穿透
ide·vscode·编辑器
jushi899910 小时前
Windows 10 LTSC 2021 二合一、四合一 极限精简版 - 小修
windows
十五年专注C++开发13 小时前
TypePerf:Windows 命令行性能计数器工具(CPU利用率、内存利用率、GPU利用率等)
c++·windows·typeperf
量子炒饭大师14 小时前
【2026全新 Claude Code + VScode + CCswitch + 接入deepseek-v4-pro 套餐】从环境配置到实战演练:Claude Code彻底开箱指南!
ide·vscode·编辑器·deepseek·claude code·cc-switch
Dvesiz14 小时前
【ClaudeCode平替(免费)】OpenCode 完整安装与 VSCode 使用指南
ide·vscode·编辑器·github·ai编程·claude·visual studio code
芯码学徒14 小时前
vscode上如何免费使用opencode插件
ide·vscode·编辑器·opencode
播播资源14 小时前
Visual Studio Code如何接入 API 使用OpenAI、claude、Gemini等最新大模型,国内直连教程
ide·vscode·编辑器