Exemplo n.º 1
0
        private void Update()
        {
            if (!MouseDownOnMe)
            {
                return;
            }

            var desiredSizeDelta = (Vector2)Input.mousePosition - MouseStartPosition;

            if (desiredSizeDelta.magnitude < 1.0f)
            {
                return;
            }

            if (IsLeft)
            {
                desiredSizeDelta.x *= -1;
            }
            if (IsBottom)
            {
                desiredSizeDelta.y *= -1;
            }

            if (!IsHorizontal || TargetStretchingInX)
            {
                desiredSizeDelta.x = 0;
            }

            if (!IsVertical || TargetStretchingInY)
            {
                desiredSizeDelta.y = 0;
            }


            var newSize = new Vector2(OriginalTargetSize.x + desiredSizeDelta.x, OriginalTargetSize.y + desiredSizeDelta.y);


            newSize = ClampSize(newSize);

            TargetTransform.sizeDelta = newSize;


            // Size done, on to position...


            var actualSizeDelta = OriginalTargetSize - newSize;

            var newPosition = OriginalTargetPosition;

            if (IsTop && !TargetStretchingInY)
            {
                newPosition.y -= actualSizeDelta.y;
            }
            if (IsLeft && !TargetStretchingInX)
            {
                newPosition.x += actualSizeDelta.x;
            }

            TargetTransform.anchoredPosition = newPosition;



            //Debug.LogFormat( "AnchorMin[{0},{1}] AnchorMax[{2},{3}]", TargetTransform.anchorMin.x,
            //    TargetTransform.anchorMin.y, TargetTransform.anchorMax.x, TargetTransform.anchorMax.y );

            if (TargetBehaviour != null)
            {
                TargetBehaviour.OnPartialResize();
            }
        }