Beispiel #1
0
        public void Resize()
        {
#if UNITY_EDITOR
            Undo.SetCurrentGroupName("GrowButtonByTextMesh Resize");
            int group = Undo.GetCurrentGroup();
#endif

            float rowWidth = RowWidth();

#if UNITY_EDITOR
            for (int i = 0; i < gameObject.transform.childCount; i++)
            {
                Undo.RecordObject(gameObject.transform.GetChild(i), "Resize Child");
            }
#endif

            textMesh.gameObject.transform.SetParent(null, true);

#if UNITY_EDITOR
            Undo.RecordObject(transform, "Scale Main Object");
#endif

            PanelUtils.PanelResizeWidth panelResizeWidth = PanelUtils.ResizeWidth(gameObject, rowWidth, 0, true);
            transform.localScale = new Vector3(panelResizeWidth.xScale, transform.localScale.y, transform.localScale.z);
            textMesh.gameObject.transform.SetParent(gameObject.transform, true);
            if (alignment == TextAlignment.Left)
            {
                // FIXME: this can be optimized by batching all WorldDistanceToLocalDistance calls for this object
                float localTextMeshWidth        = TransformWithoutRotation.WorldDistanceToLocalDistance(TextMeshWidth(), textMesh.gameObject);
                float localParentContainerWidth = TransformWithoutRotation.WorldDistanceToLocalDistance(rowWidth, textMesh.gameObject);
                float localPadding = TransformWithoutRotation.WorldDistanceToLocalDistance(padding, textMesh.gameObject);
                float xOffset      = localTextMeshWidth / 2 + localPadding - localParentContainerWidth / 2;
                textMesh.gameObject.transform.localPosition = new Vector3(
                    xOffset * textMesh.gameObject.transform.localScale.x,
                    textMesh.gameObject.transform.localPosition.y,
                    textMesh.gameObject.transform.localPosition.z
                    );
            }
            else
            {
                textMesh.gameObject.transform.localPosition = new Vector3(0, textMesh.gameObject.transform.localPosition.y, textMesh.gameObject.transform.localPosition.z);
            }

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

            if (transform.parent)
            {
                ExecuteEvents.Execute <IChild3dWidgetResized>(transform.parent.gameObject, null, (x, y) => x.Child3dWidgetResized());
            }
        }
Beispiel #2
0
        public void Resize()
        {
#if UNITY_EDITOR
            Undo.SetCurrentGroupName("PanelContainer Resize");
            int group = Undo.GetCurrentGroup();
#endif

            CalculateBounds();

            float maxWidth  = bounds.size.x;
            float maxHeight = bounds.size.y;

#if UNITY_EDITOR
            for (int i = 0; i < gameObject.transform.childCount; i++)
            {
                Undo.RecordObject(gameObject.transform.GetChild(i), "Resize Child");
            }
#endif

            Transform[] children = DetachReattach.DetachChildren(gameObject);

#if UNITY_EDITOR
            Undo.RecordObject(transform, "Resize Panel");
#endif

            PanelUtils.PanelResizeWidth  panelResizeWidth  = PanelUtils.ResizeWidth(gameObject, maxWidth, 0);
            PanelUtils.PanelResizeHeight panelResizeHeight = PanelUtils.ResizeHeight(gameObject, maxHeight, 0);
            if (panelResizeWidth.xScale > 0 && panelResizeHeight.yScale > 0)
            {
                transform.localScale = new Vector3(panelResizeWidth.xScale, panelResizeHeight.yScale, transform.localScale.z);
            }

            DetachReattach.ReattachChildren(children, gameObject);

            transform.position = transform.position + transform.right * panelResizeWidth.xOffset + transform.up * panelResizeHeight.yOffset;

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

            dirty = false;
        }