Esempio n. 1
0
        /// <summary>
        /// 获得全部的Transform
        /// </summary>
        public static Transform[] GetAllTransform(Transform rootTrans, ContainOption containOption = ContainOption.All)
        {
            if (rootTrans == null)
            {
                return(null);
            }
            if (containOption == ContainOption.OnlySelf)
            {
                return(new Transform[] { rootTrans });
            }
            List <Transform> openList  = new List <Transform>();
            List <Transform> closeList = new List <Transform>();

            openList.Add(rootTrans);
            while (openList.Count > 0)
            {
                var curTrans = openList[0];
                openList.RemoveAt(0);
                if (curTrans.childCount > 0)
                {
                    for (int i = curTrans.childCount - 1; i >= 0; i--)
                    {
                        openList.Add(curTrans.GetChild(i));
                    }
                }
                closeList.Add(curTrans);
            }
            if (containOption == ContainOption.ExceptSelf)
            {
                closeList.Remove(rootTrans);
            }
            return(closeList.ToArray());
        }
Esempio n. 2
0
 //设置层级
 public static void SetLayer(Transform rootTrans, int layer, ContainOption containOption = ContainOption.All)
 {
     foreach (var aTrans in GetAllTransform(rootTrans, containOption))
     {
         aTrans.gameObject.layer = layer;
     }
 }
Esempio n. 3
0
 //全体设置RaycastTarget
 public static void SetRaycastTarget(Transform rootTrans, bool b, ContainOption containOption = ContainOption.All)
 {
     foreach (var aTrans in GetAllTransform(rootTrans, containOption))
     {
         var graphic = aTrans.GetComponent <Graphic>();
         if (graphic != null)
         {
             graphic.raycastTarget = b;
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Gets all components.
        /// </summary>
        public static T[] GetAllComponents <T>(Transform rootTrans, ContainOption containOption = ContainOption.All) where T : Component
        {
            List <T> returnList = new List <T>();

            foreach (var aTrans in GetAllTransform(rootTrans, containOption))
            {
                var t = aTrans.GetComponent <T>();
                if (t != null)
                {
                    returnList.Add(t);
                }
            }
            return(returnList.ToArray());
        }