如题需求
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
public class DestroySubComponent{
[MenuItem("Assets/Example/DestroySubComponent")]
public static void DestroySubCom()
{
UnityEngine.Object[] selection = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
foreach (Object obj in selection)
{
GameObject go = obj as GameObject;
if (go != null)
{
//获取所有子物体
foreach (Transform t in go.transform)
{
if (!t.name.Equals("Quality"))
{
UnityEngine.Object.DestroyImmediate(t.renderer, true);
MeshFilter mf = t.GetComponent<MeshFilter>();
if (mf) { UnityEngine.Object.DestroyImmediate(mf, true); }
}
}
}
}
AssetDatabase.SaveAssets();
}
}