Esempio n. 1
0
        public static void CenteredToChilds(Transform me)
        {
            var sumPositions = new Vector3(0f, 0f, 0f);

            Transform[] tempChilds = new Transform[me.childCount];
            var         i          = 0;
            var         childCount = me.childCount;

#if UNITY_EDITOR
            var tempList = me.Cast <Transform> ().ToList();
            foreach (var child in tempList)
            {
                sumPositions += child.transform.position;
                tempChilds[i] = child;
                child.parent  = null;
                i++;
            }
#else
            foreach (Transform child in transform)
            {
                sumPositions += child.position;
                child.parent  = null;
                tempChilds[i] = child;
                i++;
            }
#endif
            sumPositions /= childCount;
            me.position   = sumPositions;
            for (var j = 0; j < tempChilds.Length; j++)
            {
                tempChilds[j].SetParent(me);
            }
        }
Esempio n. 2
0
        public static Transform[] UnParentChilds(this Transform me)
        {
            var res = new Transform[me.childCount];
            var i   = 0;

#if UNITY_EDITOR
            var tempList = me.Cast <Transform> ().ToList();
            foreach (var c in tempList)
            {
                c.parent = null;
                res[i++] = c;
            }
#else
            foreach (Transform c in me)
            {
                c.parent = null;
                res[i++] = c;
            }
#endif
            return(res);
        }
Esempio n. 3
0
        public static Vector3 GetMiddlePositionChilds(this Transform me)
        {
            var sumPositions = Vector3.zero;
            var len          = 0;

            #if UNITY_EDITOR
            var tempList = me.Cast <Transform> ().ToList();
            foreach (var child in tempList)
            {
                sumPositions += child.position;
                len++;
            }
            #else
            foreach (Transform child in me)
            {
                sumPositions += child.position;
                len++;
            }
            #endif
            sumPositions /= len;
            return(sumPositions);
        }