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

相关推荐
我命由我123451 小时前
VSCode - VSCode 放大与缩小代码
前端·ide·windows·vscode·前端框架·编辑器·软件工具
PT_silver2 小时前
tryhackme——Abusing Windows Internals(进程注入)
windows·microsoft
爱炸薯条的小朋友2 小时前
C#由于获取WPF窗口名称造成的异常报错问题
windows·c#·wpf
不伤欣3 小时前
游戏设计模式 - 子类沙箱
游戏·unity·设计模式
old_power3 小时前
VSCode 工作区配置文件通用模板创建脚本
ide·vscode·编辑器
Lw老王要学习3 小时前
VScode 使用 git 提交数据到指定库的完整指南
windows·git·vscode
vortex55 小时前
在 Kali 上打造渗透测试专用的 VSCode 环境
ide·vscode·编辑器
快乐觉主吖9 小时前
Unity的日志管理类
android·unity·游戏引擎
CodeOfCC9 小时前
c语言 封装跨平台线程头文件
linux·c语言·windows
momo卡10 小时前
MinGW-w64的安装详细步骤(c_c++的编译器gcc、g++的windows版,win10、win11真实可用)
c语言·c++·windows