Unity 编辑器删除perfab里的组件

删除指定的组件

[MenuItem("Assets/Delete UIParticle")]
// 删除 UIParticle Component
private static void NewMenuOption()
{
    var objs = Selection.objects;

    foreach (var obj in objs)
    {
        GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GetAssetPath(obj));
        go.transform.GetChild(0).localScale *= go.GetComponent<UIParticle>().scale;

        MonoBehaviour[] monoBehaviours = go.GetComponentsInChildren<MonoBehaviour>(true);
        foreach (MonoBehaviour monoBehaviour in monoBehaviours)
        {

            if (monoBehaviour.GetType() == typeof(UIParticle))
            {
                GameObject.DestroyImmediate(monoBehaviour, true);
                Debug.Log(go.name);
            }
        }

        var renders =  go.GetComponentsInChildren<ParticleSystemRenderer>();
        foreach (var render in renders)
        {
            render.enabled = true;
        }

        //PrefabUtility.SetPropertyModifications(obj, new PropertyModification[0]);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
}
发布了258 篇原创文章 · 获赞 45 · 访问量 22万+

猜你喜欢

转载自blog.csdn.net/A13155283231/article/details/105519725
今日推荐