需求很简单,就是在Editor模式下删除Prefabs中的组件,直接上代码
[MenuItem("Assets/MyTools/删除组件")]
public static void RemoveComponent()
{
GameObject[] selections = Selection.gameObjects;
for(int i = 0; i < selections.Length; i++)
{
//Category:准备删除的组件
Category[] t = selections[i].GetComponentsInChildren<Category>(true);
for(int j = 0; j < t.Length; j++)
{
DestroyImmediate(t[j], true);
}
}
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}