示例#1
0
        private void ResizeToFit()
        {
            if (mChildren == null || mChildren.Length == 0)
            {
                return;
            }

            // <TODO> This code should take Axis into account

            float highest = 0;
            float lowest  = float.MaxValue;

            for (int i = 0; i < mChildren.Length; i++)
            {
                if (mChildren[i] == null)
                {
                    continue;
                }

                Rect rect = mChildren[i].MyTransform.rect;

                float pos = mAxis == RectTransform.Axis.Vertical
                                        ? mChildren[i].MyTransform.anchoredPosition.y
                                        : mChildren[i].MyTransform.anchoredPosition.x;

                float min = pos + (mAxis == RectTransform.Axis.Vertical ? rect.yMin : rect.xMin);
                float max = pos + (mAxis == RectTransform.Axis.Vertical ? rect.yMax : rect.xMax);

                if (min < lowest)
                {
                    lowest = min;
                }
                if (max > highest)
                {
                    highest = max;
                }
            }

            float size = highest - lowest;

            size += mPaddingHigh;

            //Debug.Log("Highest: " + highest + ", lowest: " + lowest + ", size: " + size);

            MyTransform.SetSizeWithCurrentAnchors(mAxis, size);
        }
 public override void ExecuteLayout()
 {
     // Fit rect to text
     MyTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Mathf.Max(mText.preferredHeight, mMinHeight));
 }