Пример #1
0
        /// <summary>
        /// Fits RectTransform to screen.
        /// </summary>
        /// <param name="transform">Transform.</param>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="left">Left edge of alternative position.</param>
        /// <param name="bottom">Bottom edge of alternative position.</param>
        /// <param name="shadowRight">Shadow right offset.</param>
        /// <param name="shadowBottom">Shadow bottom offset.</param>
        public static void FitRectTransformToScreen(
            RectTransform transform
            , float width
            , float height
            , float x            = 0f
            , float y            = 0f
            , float left         = -1f
            , float bottom       = -1f
            , float shadowRight  = 0f
            , float shadowBottom = 0f
            )
        {
            DebugEx.VeryVerboseFormat("Utils.FitRectTransformToScreen(transform = {0}, width = {1}, height = {2}, x = {3}, y = {4}, left = {5}, bottom = {6}, shadowRight = {7}, shadowBottom = {8})"
                                      , transform
                                      , width
                                      , height
                                      , x
                                      , y
                                      , left
                                      , bottom
                                      , shadowRight
                                      , shadowBottom);

            float screenWidth  = scaledScreenWidth;
            float screenHeight = scaledScreenHeight;

            if (width > screenWidth)
            {
                width = screenWidth;
            }

            if (height > screenHeight)
            {
                height = screenHeight;
            }

            if (x + width > screenWidth)
            {
                if (left != -1f)
                {
                    x = left - width + shadowRight;

                    if (x < 0f)
                    {
                        x = screenWidth - width;
                    }
                }
                else
                {
                    x = screenWidth - width;
                }
            }

            if (y + height > screenHeight)
            {
                if (bottom != -1f)
                {
                    y = bottom - height + shadowBottom;

                    if (y < 0f)
                    {
                        y = screenHeight - height;
                    }
                }
                else
                {
                    y = screenHeight - height;
                }
            }

            Utils.AlignRectTransformTopLeft(transform, width, height, x, y);
        }