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

相关推荐
南無忘码至尊21 分钟前
Unity学习90天-第2天-认识Unity生命周期函数并用 Update 控制物体移动,FixedUpdate 控制物理
学习·unity·游戏引擎
无限进步_1 小时前
【C++】只出现一次的数字 II:位运算的三种解法深度解析
数据结构·c++·ide·windows·git·算法·leetcode
0xDevNull3 小时前
Windows系统使用nvm实现多版本切换Node.js详细教程
windows·node.js
无限进步_3 小时前
【C++】多重继承中的虚表布局分析:D类对象为何有两个虚表?
开发语言·c++·ide·windows·git·算法·visual studio
学Linux的语莫3 小时前
Hyper-V的安装使用
linux·windows·ubuntu·hyper-v
小林up4 小时前
【Unity URP源码阅读1】ColorGradingLUT
unity·游戏引擎
xiaoshuaishuai84 小时前
C# 方言识别
开发语言·windows·c#
十五年专注C++开发7 小时前
cpolar(极点云): 一款主流的内网穿透工具
linux·windows·cpolar·穿透
非凡ghost7 小时前
AIMP(音乐播放软件)
前端·windows·音视频·firefox
xifangge20257 小时前
【2026终极解法】彻底解决“由于找不到 msvcp140.dll,无法继续执行代码”报错(附微软运行库一键修复包)
windows·mysql·microsoft·报错·开发环境