void Adjust()
        {
            // Calculate new size.
            float width        = widget.width;
            float height       = widget.height;
            float targetAspect = (float)targetWidget.width / (float)targetWidget.height;             // Calculate aspect on the fly (!)
            float aspect       = targetAspect * multiplier;

            EPPZ.NGUI.SizeConstraintType constraint = EPPZ.NGUI.SizeConstraintType.Height;

            if (keepAspectRatio == EPPZ.NGUI.AspectConstraintType.BasedOnWidth)
            {
                height     = width / aspect;
                constraint = EPPZ.NGUI.SizeConstraintType.Height;
            }

            if (keepAspectRatio == EPPZ.NGUI.AspectConstraintType.BasedOnHeight)
            {
                width      = height * aspect;
                constraint = EPPZ.NGUI.SizeConstraintType.Width;
            }

            // Do actual (NGUI safe) layout.
            widget.AdjustSize(
                width,
                height,
                constraint
                );
        }
Beispiel #2
0
        public static void AdjustSize(this UIWidget widget, float width, float height, EPPZ.NGUI.SizeConstraintType constraint)
        {
            // Get size difference.
            float widthDifference  = width - widget.width;
            float heightDifference = height - widget.height;

            float leftDifference   = 0.0f;
            float bottomDifference = 0.0f;
            float rightDifference  = 0.0f;
            float topDifference    = 0.0f;

            // Calculate horizontal differences.
            if (constraint == EPPZ.NGUI.SizeConstraintType.Width || constraint == EPPZ.NGUI.SizeConstraintType.Both)
            {
                leftDifference  = -(widget.pivotOffset.x * widthDifference);
                rightDifference = (1.0f - widget.pivotOffset.x) * widthDifference;
            }

            // Calculate vertical differences.
            if (constraint == EPPZ.NGUI.SizeConstraintType.Height || constraint == EPPZ.NGUI.SizeConstraintType.Both)
            {
                bottomDifference = -(widget.pivotOffset.y * heightDifference);
                topDifference    = (1.0f - widget.pivotOffset.y) * heightDifference;
            }

            // Adjust every internal NGUI goodie under the hood (Anchors, Serialization, Colliders, Aspect, etc.).
            NGUIMath.AdjustWidget(widget, leftDifference, bottomDifference, rightDifference, topDifference);
        }