コード例 #1
0
        private void CalculateOffset()
        {
            float localRowWidth = TransformWithoutRotation.WorldDistanceToLocalDistance(RowWidth(), gameObject);
            float xOffset;

            switch (alignment)
            {
            case TextAlignment.Left:
                xOffset = localRowWidth / 2 - parentContainerWidth / 2;
                if (log)
                {
                    Debug.Log("CalculateOffset RowWidth=" + RowWidth() + ",localRowWidth=" + localRowWidth + ",parentContainerWidth=" + parentContainerWidth + ",xOffset=" + xOffset);
                }
                transform.localPosition = new Vector3(xOffset * transform.localScale.x, transform.localPosition.y, transform.localPosition.z);
                break;

            case TextAlignment.Center:
                transform.localPosition = new Vector3(0, transform.localPosition.y, transform.localPosition.z);
                break;

            case TextAlignment.Right:
                xOffset = -localRowWidth / 2 + parentContainerWidth / 2;
                if (log)
                {
                    Debug.Log("CalculateOffset RowWidth=" + RowWidth() + ",localRowWidth=" + localRowWidth + ",parentContainerWidth=" + parentContainerWidth + ",xOffset=" + xOffset);
                }
                transform.localPosition = new Vector3(xOffset * transform.localScale.x, transform.localPosition.y, transform.localPosition.z);
                break;
            }
        }
コード例 #2
0
 public void SetParentContainerWidth(float value)
 {
     parentContainerWidth = TransformWithoutRotation.WorldDistanceToLocalDistance(value, gameObject);
     if (log)
     {
         Debug.Log("SetParentContainerWidth value=" + value + ",parentContainerWidth=" + parentContainerWidth);
     }
     CalculateOffset();
 }
コード例 #3
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());
        }
コード例 #4
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());
            }
        }