Example #1
0
        protected void UpdateLayout()
        {
            if (_content2 == null && _content.texture == null && _content.frames == null)
            {
                if (_autoSize)
                {
                    _updatingLayout = true;
                    SetSize(50, 30);
                    _updatingLayout = false;
                }
                return;
            }

            float contentWidth  = sourceWidth;
            float contentHeight = sourceHeight;

            if (_autoSize)
            {
                _updatingLayout = true;
                if (contentWidth == 0)
                {
                    contentWidth = 50;
                }
                if (contentHeight == 0)
                {
                    contentHeight = 30;
                }
                SetSize(contentWidth, contentHeight);

                _updatingLayout = false;

                if (_width == contentWidth && _height == contentHeight)
                {
                    if (_content2 != null)
                    {
                        _content2.SetXY(0, 0);
                        _content2.SetScale(1, 1);
                    }
                    else
                    {
                        _content.SetXY(0, 0);
                        _content.SetSize(contentWidth, contentHeight);
                    }

                    InvalidateBatchingState();
                    return;
                }
                //如果不相等,可能是由于大小限制造成的,要后续处理
            }

            float sx = 1, sy = 1;

            if (_fill != FillType.None)
            {
                sx = this.width / sourceWidth;
                sy = this.height / sourceHeight;

                if (sx != 1 || sy != 1)
                {
                    if (_fill == FillType.ScaleMatchHeight)
                    {
                        sx = sy;
                    }
                    else if (_fill == FillType.ScaleMatchWidth)
                    {
                        sy = sx;
                    }
                    else if (_fill == FillType.Scale)
                    {
                        if (sx > sy)
                        {
                            sx = sy;
                        }
                        else
                        {
                            sy = sx;
                        }
                    }
                    else if (_fill == FillType.ScaleNoBorder)
                    {
                        if (sx > sy)
                        {
                            sy = sx;
                        }
                        else
                        {
                            sx = sy;
                        }
                    }

                    if (_shrinkOnly)
                    {
                        if (sx > 1)
                        {
                            sx = 1;
                        }
                        if (sy > 1)
                        {
                            sy = 1;
                        }
                    }

                    contentWidth  = sourceWidth * sx;
                    contentHeight = sourceHeight * sy;
                }
            }

            if (_content2 != null)
            {
                _content2.SetScale(sx, sy);
            }
            else
            {
                _content.size = new Vector2(contentWidth, contentHeight);
            }

            float nx;
            float ny;

            if (_align == AlignType.Center)
            {
                nx = (this.width - contentWidth) / 2;
            }
            else if (_align == AlignType.Right)
            {
                nx = this.width - contentWidth;
            }
            else
            {
                nx = 0;
            }
            if (_verticalAlign == VertAlignType.Middle)
            {
                ny = (this.height - contentHeight) / 2;
            }
            else if (_verticalAlign == VertAlignType.Bottom)
            {
                ny = this.height - contentHeight;
            }
            else
            {
                ny = 0;
            }
            if (_content2 != null)
            {
                _content2.SetXY(nx, ny);
            }
            else
            {
                _content.SetXY(nx, ny);
            }

            InvalidateBatchingState();
        }
Example #2
0
        void HandleScreenSizeChanged()
        {
            if (!Application.isPlaying)
            {
                DisplayOptions.SetEditModeHideFlags();
            }

            screenSizeVer = StageCamera.screenSizeVer;

            if (this.container != null)
            {
                if (this.container.renderMode != RenderMode.WorldSpace)
                {
                    this.container.scale = new Vector2(StageCamera.UnitsPerPixel * UIContentScaler.scaleFactor, StageCamera.UnitsPerPixel * UIContentScaler.scaleFactor);
                }
            }

            int width  = Mathf.CeilToInt(Screen.width / UIContentScaler.scaleFactor);
            int height = Mathf.CeilToInt(Screen.height / UIContentScaler.scaleFactor);

            if (_ui != null)
            {
                switch (fitScreen)
                {
                case FitScreen.FitSize:
                    _ui.SetSize(width, height);
                    _ui.SetXY(0, 0, true);
                    break;

                case FitScreen.FitWidthAndSetMiddle:
                    _ui.SetSize(width, _ui.sourceHeight);
                    _ui.SetXY(0, (int)((height - _ui.sourceHeight) / 2), true);
                    break;

                case FitScreen.FitHeightAndSetCenter:
                    _ui.SetSize(_ui.sourceWidth, height);
                    _ui.SetXY((int)((width - _ui.sourceWidth) / 2), 0, true);
                    break;
                }

                UpdateHitArea();
            }
            else
            {
                switch (fitScreen)
                {
                case FitScreen.FitSize:
                    uiBounds.position = new Vector2(0, 0);
                    uiBounds.size     = new Vector2(width, height);
                    break;

                case FitScreen.FitWidthAndSetMiddle:
                    uiBounds.position = new Vector2(0, (int)((height - cachedUISize.y) / 2));
                    uiBounds.size     = new Vector2(width, cachedUISize.y);
                    break;

                case FitScreen.FitHeightAndSetCenter:
                    uiBounds.position = new Vector2((int)((width - cachedUISize.x) / 2), 0);
                    uiBounds.size     = new Vector2(cachedUISize.x, height);
                    break;
                }
            }
        }
Example #3
0
        private void UpdateLayout()
        {
            if (_content2 == null && _content.texture == null && _content.frameCount == 0)
            {
                if (_autoSize)
                {
                    _updatingLayout = true;
                    this.SetSize(50, 30);
                    _updatingLayout = false;
                }
                return;
            }

            _contentWidth  = _contentSourceWidth;
            _contentHeight = _contentSourceHeight;

            if (_autoSize)
            {
                _updatingLayout = true;
                if (_contentWidth == 0)
                {
                    _contentWidth = 50;
                }
                if (_contentHeight == 0)
                {
                    _contentHeight = 30;
                }
                this.SetSize(_contentWidth, _contentHeight);
                _updatingLayout = false;

                if (_width == _contentWidth && _height == _contentHeight)
                {
                    if (_content2 != null)
                    {
                        _content2.SetXY(0, 0);
                        _content2.SetScale(1, 1);
                    }
                    else
                    {
                        _content.SetXY(0, 0);
                        _content.SetScale(1, 1);
                        if (_content.texture != null)
                        {
                            _content.SetNativeSize();
                        }
                    }
                    return;
                }
                //如果不相等,可能是由于大小限制造成的,要后续处理
            }

            float sx = 1, sy = 1;

            if (_fill != FillType.None)
            {
                sx = this.width / _contentSourceWidth;
                sy = this.height / _contentSourceHeight;

                if (sx != 1 || sy != 1)
                {
                    if (_fill == FillType.ScaleMatchHeight)
                    {
                        sx = sy;
                    }
                    else if (_fill == FillType.ScaleMatchWidth)
                    {
                        sy = sx;
                    }
                    else if (_fill == FillType.Scale)
                    {
                        if (sx > sy)
                        {
                            sx = sy;
                        }
                        else
                        {
                            sy = sx;
                        }
                    }
                    else if (_fill == FillType.ScaleNoBorder)
                    {
                        if (sx > sy)
                        {
                            sy = sx;
                        }
                        else
                        {
                            sx = sy;
                        }
                    }

                    if (_shrinkOnly)
                    {
                        if (sx > 1)
                        {
                            sx = 1;
                        }
                        if (sy > 1)
                        {
                            sy = 1;
                        }
                    }

                    _contentWidth  = Mathf.FloorToInt(_contentSourceWidth * sx);
                    _contentHeight = Mathf.FloorToInt(_contentSourceHeight * sy);
                }
            }

            if (_content2 != null)
            {
                _content2.SetScale(sx, sy);
            }
            else if (_content.texture != null)
            {
                _content.SetScale(1, 1);
                _content.size = new Vector2(_contentWidth, _contentHeight);
            }
            else
            {
                _content.SetScale(sx, sy);
            }

            float nx;
            float ny;

            if (_align == AlignType.Center)
            {
                nx = Mathf.FloorToInt((this.width - _contentWidth) / 2);
            }
            else if (_align == AlignType.Right)
            {
                nx = Mathf.FloorToInt(this.width - _contentWidth);
            }
            else
            {
                nx = 0;
            }
            if (_verticalAlign == VertAlignType.Middle)
            {
                ny = Mathf.FloorToInt((this.height - _contentHeight) / 2);
            }
            else if (_verticalAlign == VertAlignType.Bottom)
            {
                ny = Mathf.FloorToInt(this.height - _contentHeight);
            }
            else
            {
                ny = 0;
            }
            if (_content2 != null)
            {
                _content2.SetXY(nx, ny);
            }
            else
            {
                _content.SetXY(nx, ny);
            }
        }
Example #4
0
        void HandleScreenSizeChanged()
        {
            if (!Application.isPlaying)
            {
                DisplayObject.hideFlags = HideFlags.DontSaveInEditor;
            }

            screenSizeVer = StageCamera.screenSizeVer;

            int width  = Screen.width;
            int height = Screen.height;

            if (this.container != null)
            {
                Camera cam = container.GetRenderCamera();
                if (cam.targetDisplay != 0 && cam.targetDisplay < Display.displays.Length)
                {
                    width  = Display.displays[cam.targetDisplay].renderingWidth;
                    height = Display.displays[cam.targetDisplay].renderingHeight;
                }

                if (this.container.renderMode != RenderMode.WorldSpace)
                {
                    StageCamera sc = cam.GetComponent <StageCamera>();
                    if (sc == null)
                    {
                        sc = StageCamera.main.GetComponent <StageCamera>();
                    }
                    this.container.scale = new Vector2(sc.unitsPerPixel * UIContentScaler.scaleFactor, sc.unitsPerPixel * UIContentScaler.scaleFactor);
                }
            }

            width  = Mathf.CeilToInt(width / UIContentScaler.scaleFactor);
            height = Mathf.CeilToInt(height / UIContentScaler.scaleFactor);
            if (_ui != null)
            {
                switch (fitScreen)
                {
                case FitScreen.FitSize:
                    _ui.SetSize(width, height);
                    _ui.SetXY(0, 0, true);
                    break;

                case FitScreen.FitWidthAndSetMiddle:
                    _ui.SetSize(width, _ui.sourceHeight);
                    _ui.SetXY(0, (int)((height - _ui.sourceHeight) / 2), true);
                    break;

                case FitScreen.FitHeightAndSetCenter:
                    _ui.SetSize(_ui.sourceWidth, height);
                    _ui.SetXY((int)((width - _ui.sourceWidth) / 2), 0, true);
                    break;
                }

                UpdateHitArea();
            }
            else
            {
                switch (fitScreen)
                {
                case FitScreen.FitSize:
                    uiBounds.position = new Vector2(0, 0);
                    uiBounds.size     = new Vector2(width, height);
                    break;

                case FitScreen.FitWidthAndSetMiddle:
                    uiBounds.position = new Vector2(0, (int)((height - cachedUISize.y) / 2));
                    uiBounds.size     = new Vector2(width, cachedUISize.y);
                    break;

                case FitScreen.FitHeightAndSetCenter:
                    uiBounds.position = new Vector2((int)((width - cachedUISize.x) / 2), 0);
                    uiBounds.size     = new Vector2(cachedUISize.x, height);
                    break;
                }
            }
        }