Exemple #1
0
        public static void Resize(UIElement script, bool child = true)
        {
            Transform rect  = script.transform;
            Vector2   psize = Vector2.zero;
            Vector2   v     = script.m_sizeDelta;
            var       pp    = Anchors[0];

            if (script.parentType == ParentType.Tranfrom)
            {
                var p = rect.parent;
                if (p != null)
                {
                    var t = p.GetComponent <UIElement>();
                    if (t != null)
                    {
                        psize = t.SizeDelta;
                        pp    = t.Pivot;
                    }
                }
            }
            else
            {
                var t = rect.root.GetComponent <UIElement>();
                if (t != null)
                {
                    psize = t.SizeDelta;
                }
            }
            switch (script.marginType)
            {
            case MarginType.None:
                break;

            case MarginType.Margin:
                MarginEx(script, script.margin, pp, psize);
                break;

            case MarginType.MarginRatio:
                var mar = new Margin();
                mar.left  = script.margin.left * psize.x;
                mar.right = script.margin.right * psize.x;
                mar.top   = script.margin.top * psize.y;
                mar.down  = script.margin.down * psize.y;
                MarginEx(script, mar, pp, psize);
                break;

            case MarginType.MarginX:
                MarginX(script, script.margin, pp, psize);
                break;

            case MarginType.MarginY:
                MarginY(script, script.margin, pp, psize);
                break;

            case MarginType.MarginRatioX:
                mar       = new Margin();
                mar.left  = script.margin.left * psize.x;
                mar.right = script.margin.right * psize.x;
                MarginX(script, mar, pp, psize);
                break;

            case MarginType.MarginRatioY:
                mar      = new Margin();
                mar.top  = script.margin.top * psize.y;
                mar.down = script.margin.down * psize.y;
                MarginY(script, mar, pp, psize);
                break;

            case MarginType.Size:
                script.m_sizeDelta.x = psize.x - script.margin.left;
                script.m_sizeDelta.y = psize.y - script.margin.down;
                break;

            case MarginType.Ratio:
                script.m_sizeDelta.x = psize.x * (1 - script.margin.left);
                script.m_sizeDelta.y = psize.y * (1 - script.margin.down);
                break;

            case MarginType.SizeX:
                script.m_sizeDelta.x = psize.x - script.margin.left;
                break;

            case MarginType.SizeY:
                script.m_sizeDelta.y = psize.y - script.margin.down;
                break;

            case MarginType.RatioX:
                script.m_sizeDelta.x = psize.x * (1 - script.margin.left);
                break;

            case MarginType.RatioY:
                script.m_sizeDelta.y = psize.y * (1 - script.margin.down);
                break;
            }
            switch (script.anchorType)
            {
            case AnchorType.None:
                break;

            case AnchorType.Anchor:
                AnchorEx(script, script.anchorPointType, script.anchorOffset, pp, psize);
                break;

            case AnchorType.Alignment:
                AlignmentEx(script, script.anchorPointType, script.anchorOffset, pp, psize);
                break;
            }
            if (script.scaleType != ScaleType.None)
            {
                Scaling(script, script.scaleType, psize, script.m_sizeDelta);
            }
            if (child)
            {
                ResizeChild(rect, child);
            }
            if (script.scaleType != ScaleType.None | script.anchorType != AnchorType.None | script.marginType != MarginType.None)
            {
                ResizeChild(rect, false);
                if (v != script.m_sizeDelta)
                {
                    script.ReSized();
                }
            }
        }
Exemple #2
0
        public static void Resize(UIElement script, bool child = true)
        {
            Transform rect    = script.transform;
            Vector3   loclpos = rect.localPosition;
            Vector2   psize   = Vector2.zero;
            Vector2   v       = script.m_sizeDelta;
            var       pp      = Anchors[0];

            if (script.parentType == ParentType.Tranfrom)
            {
                var p = rect.parent;
                if (p != null)
                {
                    var t = p.GetComponent <UIElement>();
                    if (t != null)
                    {
                        psize = t.SizeDelta;
                        pp    = t.Pivot;
                    }
                }
            }
            else
            {
                var t = rect.root.GetComponent <UIElement>();
                if (t != null)
                {
                    psize = t.SizeDelta;
                }
            }
            switch (script.marginType)
            {
            case MarginType.None:
                break;

            case MarginType.Margin:
                var mar = script.margin;
                if (script.parentType == ParentType.BangsScreen)
                {
                    if (Scale.ScreenHeight / Scale.ScreenWidth > 2f)
                    {
                        mar.top += 88;
                    }
                }
                MarginEx(script, mar, pp, psize);
                break;

            case MarginType.MarginRatio:
                mar       = new Margin();
                mar.left  = script.margin.left * psize.x;
                mar.right = script.margin.right * psize.x;
                mar.top   = script.margin.top * psize.y;
                if (script.parentType == ParentType.BangsScreen)
                {
                    if (Scale.ScreenHeight / Scale.ScreenWidth > 2f)
                    {
                        mar.top += 88;
                    }
                }
                mar.down = script.margin.down * psize.y;
                MarginEx(script, mar, pp, psize);
                break;

            case MarginType.MarginX:
                mar = script.margin;
                if (script.parentType == ParentType.BangsScreen)
                {
                    if (Scale.ScreenHeight / Scale.ScreenWidth > 2f)
                    {
                        mar.top += 88;
                    }
                }
                MarginX(script, mar, pp, psize);
                break;

            case MarginType.MarginY:
                mar = script.margin;
                if (script.parentType == ParentType.BangsScreen)
                {
                    if (Scale.ScreenHeight / Scale.ScreenWidth > 2f)
                    {
                        mar.top += 88;
                    }
                }
                MarginY(script, mar, pp, psize);
                break;

            case MarginType.MarginRatioX:
                break;

            case MarginType.MarginRatioY:
                break;
            }
            //Scaling(script, script.scaleType, psize, script.DesignSize);
            switch (script.anchorType)
            {
            case AnchorType.None:
                break;

            case AnchorType.Anchor:
                AnchorEx(script, script.anchorPointType, script.anchorOffset, pp, psize);
                break;

            case AnchorType.Alignment:
                AlignmentEx(script, script.anchorPointType, script.anchorOffset, pp, psize);
                break;
            }

            if (child)
            {
                ResizeChild(rect, child);
            }
            else if (script.scaleType != ScaleType.None | script.anchorType != AnchorType.None | script.marginType != MarginType.None)
            {
                ResizeChild(rect, false);
                if (v != script.m_sizeDelta)
                {
                    script.ReSized();
                }
            }
        }