zoukankan      html  css  js  c++  java
  • 删除GameObject上除了Quality子物体之外其他子物体的组件(但不删除transform)


    如题需求

    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();
        }
    }

  • 相关阅读:
    51Nod1355 斐波那契的最小公倍数
    Topcoder CyclesNumber 和 ARC96E Everything on It
    CF1236F Alice and the Cactus
    Projecteuler522 Hilbert's Blackout
    Projecteuler584 Birthday Problem Revisited
    CF1187F Expected Square Beauty
    BZOJ3451 Normal 和 CF235D Graph Game
    CF1153F Serval and Bonus Problem
    CTSC2006 歌唱王国
    SDOI2012 走迷宫 和 Gym100591D Fox Rocks
  • 原文地址:https://www.cnblogs.com/oldman/p/2597706.html
Copyright © 2011-2022 走看看