先看演示效果
实现方案
1创建几个用于测试的cube
2,创建一个Editor脚本
3,编写脚本内容
附上源码
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.赶紧去试试吧,对获取到的预制件做自己的逻辑处理