Unity移除空组件工具
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace Editor_BRK
{
public class RemoveNullComponent
{
[MenuItem("Tools/移除选中物体以下层级的空组件")]
private static void SelectionGameObj()
{
GameObject[] gos = Selection.gameObjects;
for (int i = 0; i < gos.Length; i++)
{
RemoveComponent(gos[i]);
}
}
private static void RemoveComponent(GameObject component)
{
Transform[] transforms = component.GetComponentsInChildren<Transform>(true);
for (int j = 0; j < transforms.Length; j++)
{
GameObject obj = transforms[j].gameObject;
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(obj);
Debug.Log(obj.name + "已经移除空脚本");
AssetDatabase.Refresh();
}
}
}
}
|