예제 #1
0
        public void MoveChildren()
        {
            float widthSoFar = padding;
            float maxHeight  = 0;

            float rowWidth = RowWidth();

#if UNITY_EDITOR
            Undo.SetCurrentGroupName("RowContainer MoveChildren");
            int group = Undo.GetCurrentGroup();
#endif

            for (int i = 0; i < transform.childCount; i++)
            {
                Transform child = transform.GetChild(i);
                if (!child.gameObject.activeSelf)
                {
                    continue;
                }

                float width  = ObjectBounds.WorldWidth(child.gameObject);
                float height = ObjectBounds.WorldHeight(child.gameObject);

                if (height > maxHeight)
                {
                    maxHeight = height;
                }

                float localX = TransformWithoutRotation.WorldDistanceToLocalDistance(widthSoFar + width / 2 - rowWidth / 2, gameObject);

#if UNITY_EDITOR
                Undo.RecordObject(child.transform, "Move Child");
#endif
                child.localPosition = new Vector3(localX, 0, child.localPosition.z);

                if (i == transform.childCount - 1)
                {
                    widthSoFar += width + padding;
                }
                else
                {
                    widthSoFar += width + spacing;
                }
            }

            bounds.size = new Vector3(rowWidth, maxHeight, 0);

#if UNITY_EDITOR
            Undo.CollapseUndoOperations(group);
#endif

            ExecuteEvents.Execute <IChild3dWidgetResized>(transform.parent.gameObject, null, (x, y) => x.Child3dWidgetResized());
        }
        public void MoveChildren()
        {
            float heightSoFar = padding;
            float maxWidth    = 0;

            float columnHeight = ColumnHeight();

#if UNITY_EDITOR
            Undo.SetCurrentGroupName("ColumnContainer MoveChildren");
            int group = Undo.GetCurrentGroup();
#endif

            for (int i = 0; i < transform.childCount; i++)
            {
                Transform child = transform.GetChild(i);
                if (!child.gameObject.activeSelf)
                {
                    continue;
                }

                float height = ObjectBounds.WorldHeight(child.gameObject);
                float width  = ObjectBounds.WorldWidth(child.gameObject);

                if (width > maxWidth)
                {
                    maxWidth = width;
                }

                float localY = TransformWithoutRotation.WorldDistanceToLocalDistanceY(-heightSoFar - height / 2 + columnHeight / 2, gameObject);
#if UNITY_EDITOR
                Undo.RecordObject(child.transform, "Move Child");
#endif
                child.localPosition = new Vector3(child.localPosition.x, localY, child.localPosition.z);

                if (i == transform.childCount - 1)
                {
                    heightSoFar += height + padding;
                }
                else
                {
                    heightSoFar += height + spacing;
                }
            }

            bounds.size = new Vector3(maxWidth, columnHeight, 0);
#if UNITY_EDITOR
            Undo.CollapseUndoOperations(group);
#endif
            BroadcastContainerWidth();

            ExecuteEvents.Execute <IChild3dWidgetResized>(transform.parent.gameObject, null, (x, y) => x.Child3dWidgetResized());
        }
        public float ColumnHeight()
        {
            float        height  = padding * 2;
            List <float> heights = new List <float>();

            foreach (Transform child in transform)
            {
                if (!child.gameObject.activeSelf)
                {
                    continue;
                }
                heights.Add(ObjectBounds.WorldHeight(child.gameObject));
            }

            height += PanelUtils.SumWithSpacing(heights, spacing);

            return(height);
        }
예제 #4
0
        public void CalculateBounds()
        {
            float maxWidth  = 0;
            float maxHeight = 0;

            for (int i = 0; i < transform.childCount; i++)
            {
                Transform child  = transform.GetChild(i);
                float     height = ObjectBounds.WorldHeight(child.gameObject);
                float     width  = ObjectBounds.WorldWidth(child.gameObject);

                if (width > maxWidth)
                {
                    maxWidth = width;
                }
                if (height > maxHeight)
                {
                    maxHeight = height;
                }
            }

            bounds.size = new Vector3(maxWidth, maxHeight, 0);
        }