using UnityEngine;
using System.Collections;
using UnityEditor;
public class OnSearchPrefabForReferences : EditorWindow
{
[MenuItem("Tools/Finder/Check Prefab Use ?")]
private static void OnSearchForReferences()
{
//确保鼠标右键选择的是一个Prefab
if (Selection.gameObjects.Length != 1)
{
return;
}
//遍历所有游戏场景
foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
{
if (scene.enabled)
{
//打开场景
EditorApplication.OpenScene(scene.path);
//获取场景中的所有游戏对象
GameObject[] gos = (GameObject[])FindObjectsOfType(typeof(GameObject));
foreach (GameObject go in gos)
{
//判断GameObject是否为一个Prefab的引用
if (PrefabUtility.GetPrefabType(go) == PrefabType.PrefabInstance)
{
Unity寻找预设在场景中的所有引用
最新推荐文章于 2022-04-24 11:36:52 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)