/// <summary>
    /// Refreshes the sprite's anchoring offsets according to its parent and position.
    /// </summary>
    /// <param name="sprite"></param>
    public static void refreshAnchorInformation(this IPositionable sprite)
    {
        // Get anchor info
        UIAnchorInfo anchorInfo = sprite.anchorInfo;

        // Get anchor positions
        Vector3 parentPosition = parentAnchorPosition(anchorInfo.ParentUIObject, anchorInfo.ParentUIyAnchor, anchorInfo.ParentUIxAnchor);
        Vector3 diffAnchor     = sprite.position - parentPosition;

        // Adjust for sprite anchor offset
        diffAnchor.x += UIRelative.xAnchorAdjustment(anchorInfo.UIxAnchor, sprite.width, anchorInfo.OriginUIxAnchor);
        diffAnchor.y -= UIRelative.yAnchorAdjustment(anchorInfo.UIyAnchor, sprite.height, anchorInfo.OriginUIyAnchor);

        // Adjust parent anchor offsets
        if (anchorInfo.UIPrecision == UIPrecision.Percentage)
        {
            anchorInfo.OffsetX = UIRelative.xPercentTo(anchorInfo.UIxAnchor, parentWidth(anchorInfo.ParentUIObject), diffAnchor.x);
            anchorInfo.OffsetY = -UIRelative.yPercentTo(anchorInfo.UIyAnchor, parentHeight(anchorInfo.ParentUIObject), diffAnchor.y);
        }
        else
        {
            anchorInfo.OffsetX = UIRelative.xPixelsTo(anchorInfo.UIxAnchor, diffAnchor.x);
            anchorInfo.OffsetY = -UIRelative.yPixelsTo(anchorInfo.UIyAnchor, diffAnchor.y);
        }

        // Set update anchor info
        sprite.anchorInfo = anchorInfo;
    }
示例#2
0
    /// <summary>
    /// Sets up the client GameObject along with it's layer and caches the transform
    /// </summary>
    public UIObject(GameObject prefab = null)
    {
        // Setup our GO
        if (prefab)
        {
            _client = Object.Instantiate(prefab) as GameObject;
        }
        else
        {
            _client = new GameObject(this.GetType().Name);
        }

        // Cache the clientTransform
        clientTransform = _client.transform;

        clientTransform.parent = UI.instance.transform; // Just for orginization in the hierarchy
        _client.layer          = UI.instance.layer;     // Set the proper layer so we only render on the UI camera

        UIElement uie = _client.AddComponent <UIElement>();

        uie.UIObject = this;


        // Create a default anchor info object
        _anchorInfo = UIAnchorInfo.DefaultAnchorInfo();
    }
示例#3
0
    /// <summary>
    /// Sets up the client GameObject along with it's layer and caches the transform
    /// </summary>
    public UIObject()
    {
        // Setup our GO
        _client = new GameObject( this.GetType().Name );
        _client.transform.parent = UI.instance.transform; // Just for orginization in the hierarchy
        _client.layer = UI.instance.layer; // Set the proper layer so we only render on the UI camera

        // Cache the clientTransform
        clientTransform = _client.transform;
        // Create a default anchor info object
        _anchorInfo = UIAnchorInfo.DefaultAnchorInfo();
    }
示例#4
0
    /// <summary>
    /// Sets up the client GameObject along with it's layer and caches the transform
    /// </summary>
    public UIObject()
    {
        // Setup our GO
        _client = new GameObject(this.GetType().Name);
        _client.transform.parent = UI.instance.transform; // Just for orginization in the hierarchy
        _client.layer            = UI.instance.layer;     // Set the proper layer so we only render on the UI camera

        // Cache the clientTransform
        clientTransform = _client.transform;
        // Create a default anchor info object
        _anchorInfo = UIAnchorInfo.DefaultAnchorInfo();
    }
    public UIGridLayout(int columns, int rows, int cellPadding)
        : base(UIAbstractContainer.UILayoutType.AbsoluteLayout)           //don't manage layout for us
    {
        //padding
        _spacing = cellPadding;

        this.columns = columns;
        this.rows    = rows;

        //top left
        m_gridAnchor = UIAnchorInfo.DefaultAnchorInfo();
        m_gridAnchor.ParentUIObject = this;
        m_gridAnchor.UIPrecision    = UIPrecision.Pixel;
    }
	public UIGridLayout( int columns, int rows, int cellPadding ) 
		: base( UIAbstractContainer.UILayoutType.AbsoluteLayout ) //don't manage layout for us
	{
		//padding
		_spacing = cellPadding;
		
		this.columns = columns;
		this.rows = rows;
		
		//top left
		m_gridAnchor = UIAnchorInfo.DefaultAnchorInfo();
		m_gridAnchor.ParentUIObject = this;
		m_gridAnchor.UIPrecision = UIPrecision.Pixel;
	}
    //helper functions
    UIAnchorInfo GetCellAnchorFor(int column, int row)
    {
        float cellWidth  = Screen.width / columns;
        float cellHeight = Screen.height / rows;

        var cellAnchor = UIAnchorInfo.DefaultAnchorInfo();

        cellAnchor.ParentUIObject  = this;
        cellAnchor.ParentUIxAnchor = m_gridAnchor.OriginUIxAnchor;
        cellAnchor.ParentUIyAnchor = m_gridAnchor.OriginUIyAnchor;
        cellAnchor.OffsetX         = UI.scaleFactor * cellWidth * column + _edgeInsets.left;
        cellAnchor.OffsetY         = UI.scaleFactor * cellHeight * row + _edgeInsets.right;

        return(cellAnchor);
    }
示例#8
0
 /// <summary>
 /// Creates a default anchor info object anchored to top left corner.
 /// </summary>
 /// <returns>Default anchor info object</returns>
 public static UIAnchorInfo DefaultAnchorInfo()
 {
     UIAnchorInfo anchorInfo = new UIAnchorInfo()
     {
         ParentUIObject = null,
         ParentUIxAnchor = UIxAnchor.Left,
         ParentUIyAnchor = UIyAnchor.Top,
         UIxAnchor = UIxAnchor.Left,
         UIyAnchor = UIyAnchor.Top,
         UIPrecision = UIPrecision.Percentage,
         OffsetX = 0f,
         OffsetY = 0f,
         OriginInCenter = false
     };
     return anchorInfo;
 }
示例#9
0
 /// <summary>
 /// Creates a default anchor info object anchored to top left corner.
 /// </summary>
 /// <returns>Default anchor info object</returns>
 public static UIAnchorInfo DefaultAnchorInfo()
 {
     UIAnchorInfo anchorInfo = new UIAnchorInfo()
     {
         ParentUIObject = null,
         ParentUIxAnchor = UIxAnchor.Left,
         ParentUIyAnchor = UIyAnchor.Top,
         UIxAnchor = UIxAnchor.Left,
         UIyAnchor = UIyAnchor.Top,
         OriginUIxAnchor = UIxAnchor.Left,
         OriginUIyAnchor = UIyAnchor.Top,
         UIPrecision = UIPrecision.Pixel,
         OffsetX = 0f,
         OffsetY = 0f
     };
     return anchorInfo;
 }
示例#10
0
    /// <summary>
    /// Creates a default anchor info object anchored to top left corner.
    /// </summary>
    /// <returns>Default anchor info object</returns>
    public static UIAnchorInfo DefaultAnchorInfo()
    {
        UIAnchorInfo anchorInfo = new UIAnchorInfo()
        {
            ParentUIObject  = null,
            ParentUIxAnchor = UIxAnchor.Left,
            ParentUIyAnchor = UIyAnchor.Top,
            UIxAnchor       = UIxAnchor.Left,
            UIyAnchor       = UIyAnchor.Top,
            OriginUIxAnchor = UIxAnchor.Left,
            OriginUIyAnchor = UIyAnchor.Top,
            UIPrecision     = UIPrecision.Pixel,
            OffsetX         = 0f,
            OffsetY         = 0f
        };

        return(anchorInfo);
    }
    /// <summary>
    /// Positions a sprite relatively to the center-right of its parent, with specific local anchors.
    /// Values are pixels to move away from the parent.
    /// </summary>
    /// <param name="sprite"></param>
    /// <param name="pixelsFromTop">Pixels from top - positive values places the sprite closer to the bottom</param>
    /// <param name="pixelsFromRight">Pixels from right - positive values places the sprite closer to the left</param>
    /// <param name="yAnchor">Sprite vertical anchor</param>
    /// <param name="xAnchor">Sprite horizontal anchor</param>
    public static void pixelsFromRight(this IPositionable sprite, int pixelsFromTop, int pixelsFromRight, UIyAnchor yAnchor, UIxAnchor xAnchor)
    {
        // Update anchor information
        UIAnchorInfo anchorInfo = sprite.anchorInfo;

        anchorInfo.ParentUIxAnchor = UIxAnchor.Right;
        anchorInfo.ParentUIyAnchor = UIyAnchor.Center;
        anchorInfo.UIxAnchor       = xAnchor;
        anchorInfo.UIyAnchor       = yAnchor;
        anchorInfo.OffsetX         = pixelsFromRight;
        anchorInfo.OffsetY         = pixelsFromTop;
        anchorInfo.UIPrecision     = UIPrecision.Pixel;

        // Set new anchor information
        sprite.anchorInfo = anchorInfo;

        // Refresh position
        sprite.refreshPosition();
    }
    /// <summary>
    /// Positions a sprite relatively to the top-left corner of its parent, with specific local anchors.
    /// Values are percentage of screen width/height to move away from the parent.
    /// </summary>
    /// <param name="sprite"></param>
    /// <param name="percentFromTop">Percentage from top - positive values places the sprite closer to the bottom</param>
    /// <param name="percentFromLeft">Percentage from left - positive values places the sprite closer to the right</param>
    /// <param name="yAnchor">Sprite vertical anchor</param>
    /// <param name="xAnchor">Sprite horizontal anchor</param>
    public static void positionFromTopLeft(this IPositionable sprite, float percentFromTop, float percentFromLeft, UIyAnchor yAnchor, UIxAnchor xAnchor)
    {
        // Update anchor information
        UIAnchorInfo anchorInfo = sprite.anchorInfo;

        anchorInfo.ParentUIxAnchor = UIxAnchor.Left;
        anchorInfo.ParentUIyAnchor = UIyAnchor.Top;
        anchorInfo.UIxAnchor       = xAnchor;
        anchorInfo.UIyAnchor       = yAnchor;
        anchorInfo.OffsetX         = percentFromLeft;
        anchorInfo.OffsetY         = percentFromTop;
        anchorInfo.UIPrecision     = UIPrecision.Percentage;

        // Set new anchor information
        sprite.anchorInfo = anchorInfo;

        // Refresh position
        sprite.refreshPosition();
    }
示例#13
0
    /// <summary>
    /// Sets up the client GameObject along with it's layer and caches the transform
    /// </summary>
    public UIObject(GameObject prefab = null)
    {
        // Setup our GO
        if (prefab) {
            _client = Object.Instantiate( prefab ) as GameObject;
        } else {
            _client = new GameObject( this.GetType().Name );
        }

        // Cache the clientTransform
        clientTransform = _client.transform;

        clientTransform.parent = UI.instance.transform; // Just for orginization in the hierarchy
        _client.layer = UI.instance.layer; // Set the proper layer so we only render on the UI camera

        UIElement uie = _client.AddComponent<UIElement>();
        uie.UIObject = this;

        // Create a default anchor info object
        _anchorInfo = UIAnchorInfo.DefaultAnchorInfo();
    }
示例#14
0
    /// <summary>
    /// Responsible for laying out the child UISprites
    /// </summary>
    protected virtual void layoutChildren()
    {
        if (_suspendUpdates)
        {
            return;
        }

        // Get HD factor
        var hdFactor = 1f / UI.scaleFactor;

        // rules for vertical and horizontal layouts
        if (_layoutType == UIAbstractContainer.UILayoutType.Horizontal || _layoutType == UIAbstractContainer.UILayoutType.Vertical)
        {
            // start with the insets, then add each object + spacing then end with insets
            _contentWidth  = _edgeInsets.left;
            _contentHeight = _edgeInsets.top;

            // create UIAnchorInfo to control positioning
            var anchorInfo = UIAnchorInfo.DefaultAnchorInfo();
            anchorInfo.ParentUIObject = this;

            if (_layoutType == UIAbstractContainer.UILayoutType.Horizontal)
            {
                // Set anchor information
                switch (_verticalAlignMode)
                {
                case UIContainerVerticalAlignMode.Top:
                    anchorInfo.UIyAnchor       = UIyAnchor.Top;
                    anchorInfo.ParentUIyAnchor = UIyAnchor.Top;
                    anchorInfo.OffsetY         = _edgeInsets.top * hdFactor;
                    break;

                case UIContainerVerticalAlignMode.Middle:
                    anchorInfo.UIyAnchor       = UIyAnchor.Center;
                    anchorInfo.ParentUIyAnchor = UIyAnchor.Center;
                    break;

                case UIContainerVerticalAlignMode.Bottom:
                    anchorInfo.UIyAnchor       = UIyAnchor.Bottom;
                    anchorInfo.ParentUIyAnchor = UIyAnchor.Bottom;
                    anchorInfo.OffsetY         = _edgeInsets.bottom * hdFactor;
                    break;
                }

                var i         = 0;
                var lastIndex = _children.Count;
                foreach (var item in _children)
                {
                    // we add spacing for all but the first and last
                    if (i != 0 && i != lastIndex)
                    {
                        _contentWidth += _spacing;
                    }

                    // Set anchor offset
                    anchorInfo.OffsetX = (_contentWidth + _scrollPosition) * hdFactor;

                    // dont overwrite the sprites origin anchor!
                    anchorInfo.OriginUIxAnchor = item.anchorInfo.OriginUIxAnchor;
                    anchorInfo.OriginUIyAnchor = item.anchorInfo.OriginUIyAnchor;

                    item.anchorInfo = anchorInfo;

                    // all items get their width added
                    _contentWidth += item.width;

                    // height will just be the height of the tallest item
                    if (_contentHeight < item.height)
                    {
                        _contentHeight = item.height;
                    }

                    i++;
                }
            }
            else             // vertical alignment
            {
                // Set anchor information
                switch (_alignMode)
                {
                case UIContainerAlignMode.Left:
                    anchorInfo.UIxAnchor       = UIxAnchor.Left;
                    anchorInfo.ParentUIxAnchor = UIxAnchor.Left;
                    anchorInfo.OffsetX         = _edgeInsets.left * hdFactor;
                    break;

                case UIContainerAlignMode.Center:
                    anchorInfo.UIxAnchor       = UIxAnchor.Center;
                    anchorInfo.ParentUIxAnchor = UIxAnchor.Center;
                    break;

                case UIContainerAlignMode.Right:
                    anchorInfo.UIxAnchor       = UIxAnchor.Right;
                    anchorInfo.ParentUIxAnchor = UIxAnchor.Right;
                    anchorInfo.OffsetX         = _edgeInsets.right * hdFactor;
                    break;
                }

                var i         = 0;
                var lastIndex = _children.Count;
                foreach (var item in _children)
                {
                    // we add spacing for all but the first and last
                    if (i != 0 && i != lastIndex)
                    {
                        _contentHeight += _spacing;
                    }

                    // Set anchor offset
                    anchorInfo.OffsetY = (_contentHeight + _scrollPosition) * hdFactor;
                    //anchorInfo.OffsetX = item.anchorInfo.OffsetX;

                    // dont overwrite the sprites origin anchor!
                    anchorInfo.OriginUIxAnchor = item.anchorInfo.OriginUIxAnchor;
                    anchorInfo.OriginUIyAnchor = item.anchorInfo.OriginUIyAnchor;
                    item.anchorInfo            = anchorInfo;

                    // all items get their height added
                    _contentHeight += item.height;

                    // width will just be the width of the widest item
                    if (_contentWidth < item.width)
                    {
                        _contentWidth = item.width;
                    }

                    i++;
                }
            }

            // add the right and bottom edge inset to finish things off
            _contentWidth  += _edgeInsets.right;
            _contentHeight += _edgeInsets.bottom;
        }
        else if (_layoutType == UIAbstractContainer.UILayoutType.AbsoluteLayout)
        {
            foreach (var item in _children)
            {
                if (!item.hidden)
                {
                    item.localPosition = new Vector3(item.position.x, item.position.y, item.position.z);

                    // find the width that contains the item with the largest offset/width
                    if (_contentWidth < item.localPosition.x + item.width)
                    {
                        _contentWidth = item.localPosition.x + item.width;
                    }

                    // find the height that contains the item with the largest offset/height
                    if (_contentHeight < -item.localPosition.y + item.height)
                    {
                        _contentHeight = -item.localPosition.y + item.height;
                    }
                }
            }
        }

        // Refresh child position to proper positions
        foreach (var item in _children)
        {
            item.refreshPosition();
        }
    }
示例#15
0
    protected override void layoutChildren()
    {
        if (_suspendUpdates)
        {
            return;
        }

        // Get HD factor
        var hdFactor = 1f / UI.scaleFactor;

        // rules for vertical and horizontal layouts
        if (layoutType == UIAbstractContainerWrap.UILayoutType.Horizontal || layoutType == UIAbstractContainerWrap.UILayoutType.Vertical)
        {
            // start with the insets, then add each object + spacing then end with insets
            _contentWidth  = _edgeInsets.left;
            _contentHeight = _edgeInsets.top;

            // create UIAnchorInfo to control positioning
            var anchorInfo = UIAnchorInfo.DefaultAnchorInfo();
            anchorInfo.ParentUIObject = this;

            if (layoutType == UIAbstractContainerWrap.UILayoutType.Horizontal)
            {
                // Set anchor information
                switch (verticalAlignMode)
                {
                case UIContainerVerticalAlignMode.Top:
                    anchorInfo.UIyAnchor       = UIyAnchor.Top;
                    anchorInfo.ParentUIyAnchor = UIyAnchor.Top;
                    anchorInfo.OffsetY         = _edgeInsets.top * hdFactor;
                    break;

                case UIContainerVerticalAlignMode.Middle:
                    anchorInfo.UIyAnchor       = UIyAnchor.Center;
                    anchorInfo.ParentUIyAnchor = UIyAnchor.Center;
                    break;

                case UIContainerVerticalAlignMode.Bottom:
                    anchorInfo.UIyAnchor       = UIyAnchor.Bottom;
                    anchorInfo.ParentUIyAnchor = UIyAnchor.Bottom;
                    anchorInfo.OffsetY         = _edgeInsets.bottom * hdFactor;
                    break;
                }

                var          i         = 0;
                var          lastIndex = _children.Count;
                float        tempWidth = 0;
                List <float> rows      = new List <float>(); rows.Add(0); // first row.
                foreach (var item in _children)
                {
                    if (item as UIAbstractContainer2 != null)
                    {
                        // -WIP----------------------------------------------------------------------
                        // we add spacing for all but the first and last
                        if (i != 0 && i != lastIndex)
                        {
                            _contentWidth += _spacing;
                        }

                        // Set anchor offset

                        if (position.x + tempWidth + ((UIAbstractContainer2)item).width > Screen.width)
                        {
                            rows.Add(0);
                            tempWidth          = 0;
                            anchorInfo.OffsetY = (_contentHeight) * hdFactor;
                        }

                        anchorInfo.OffsetX = (tempWidth + _scrollPosition) * hdFactor;
                        tempWidth         += ((UIAbstractContainer2)item).width;

                        if (rows[rows.Count - 1] < ((UIAbstractContainer2)item).height)
                        {
                            rows[rows.Count - 1] = ((UIAbstractContainer2)item).height + _spacing;
                        }

                        if (tempWidth > _contentWidth)
                        {
                            _contentWidth = tempWidth;
                        }

                        // dont overwrite the sprites origin anchor!
                        anchorInfo.OriginUIxAnchor = ((UIAbstractContainer2)item).anchorInfo.OriginUIxAnchor;
                        anchorInfo.OriginUIyAnchor = ((UIAbstractContainer2)item).anchorInfo.OriginUIyAnchor;

                        ((UIAbstractContainer2)item).anchorInfo = anchorInfo;

                        _contentHeight = 0;
                        foreach (float row in rows)
                        {
                            _contentHeight += row;
                        }
                        // --------------------------------------------------------------------------
                    }
                    else if (item as UISprite != null)
                    {
                        // -WIP----------------------------------------------------------------------
                        // we add spacing for all but the first and last
                        if (i != 0 && i != lastIndex)
                        {
                            _contentWidth += _spacing;
                        }

                        // Set anchor offset

                        if (position.x + tempWidth + ((UISprite)item).width > Screen.width)
                        {
                            rows.Add(0);
                            tempWidth          = 0;
                            anchorInfo.OffsetY = (_contentHeight) * hdFactor;
                        }

                        anchorInfo.OffsetX = (tempWidth + _scrollPosition) * hdFactor;
                        tempWidth         += ((UISprite)item).width;

                        if (rows[rows.Count - 1] < ((UISprite)item).height)
                        {
                            rows[rows.Count - 1] = ((UISprite)item).height;
                        }

                        if (tempWidth > _contentWidth)
                        {
                            _contentWidth = tempWidth;
                        }

                        // dont overwrite the sprites origin anchor!
                        anchorInfo.OriginUIxAnchor = ((UISprite)item).anchorInfo.OriginUIxAnchor;
                        anchorInfo.OriginUIyAnchor = ((UISprite)item).anchorInfo.OriginUIyAnchor;

                        ((UISprite)item).anchorInfo = anchorInfo;

                        _contentHeight = 0;
                        foreach (float row in rows)
                        {
                            _contentHeight += row;
                        }
                        // --------------------------------------------------------------------------
                    }
                    else if (item as UITextInstance != null)
                    {
                        // we add spacing for all but the first and last
                        if (i != 0 && i != lastIndex)
                        {
                            _contentHeight += _spacing;
                        }

                        // Set anchor offset
                        //anchorInfo.OffsetY = (_contentHeight + _scrollPosition) * hdFactor;
                        //anchorInfo.OffsetX = item.anchorInfo.OffsetX;

                        // Set anchor offset

                        if (position.x + tempWidth + ((UITextInstance)item).width > Screen.width)
                        {
                            rows.Add(0);
                            tempWidth          = 0;
                            anchorInfo.OffsetY = (_contentHeight) * hdFactor;
                            Debug.Log("newtextrow");
                        }

                        anchorInfo.OffsetX = (tempWidth + _scrollPosition) * hdFactor;
                        tempWidth         += ((UITextInstance)item).width;

                        if (rows[rows.Count - 1] < ((UITextInstance)item).height)
                        {
                            rows[rows.Count - 1] = ((UITextInstance)item).height;
                        }

                        if (tempWidth > _contentWidth)
                        {
                            _contentWidth = tempWidth;
                        }

                        // dont overwrite the sprites origin anchor!
                        anchorInfo.OriginUIxAnchor        = ((UITextInstance)item).anchorInfo.OriginUIxAnchor;
                        anchorInfo.OriginUIyAnchor        = ((UITextInstance)item).anchorInfo.OriginUIyAnchor;
                        ((UITextInstance)item).anchorInfo = anchorInfo;

                        // all items get their height added
                        _contentHeight += ((UITextInstance)item).height;

                        // width will just be the width of the widest item
                        if (_contentWidth < ((UITextInstance)item).width)
                        {
                            _contentWidth = ((UITextInstance)item).width;
                        }
                    }
                    i++;
                }
            }
            else             // vertical alignment
            {
                // Set anchor information
                switch (alignMode)
                {
                case UIContainerAlignMode.Left:
                    anchorInfo.UIxAnchor       = UIxAnchor.Left;
                    anchorInfo.ParentUIxAnchor = UIxAnchor.Left;
                    anchorInfo.OffsetX         = _edgeInsets.left * hdFactor;
                    break;

                case UIContainerAlignMode.Center:
                    anchorInfo.UIxAnchor       = UIxAnchor.Center;
                    anchorInfo.ParentUIxAnchor = UIxAnchor.Center;
                    break;

                case UIContainerAlignMode.Right:
                    anchorInfo.UIxAnchor       = UIxAnchor.Right;
                    anchorInfo.ParentUIxAnchor = UIxAnchor.Right;
                    anchorInfo.OffsetX         = _edgeInsets.right * hdFactor;
                    break;
                }

                var i         = 0;
                var lastIndex = _children.Count;
                foreach (var item in _children)
                {
                    if (item as UIAbstractContainer2 != null)
                    {
                        // we add spacing for all but the first and last
                        if (i != 0 && i != lastIndex)
                        {
                            _contentHeight += _spacing;
                        }

                        // Set anchor offset
                        anchorInfo.OffsetY = (_contentHeight + _scrollPosition) * hdFactor;
                        //anchorInfo.OffsetX = item.anchorInfo.OffsetX;

                        // dont overwrite the sprites origin anchor!
                        anchorInfo.OriginUIxAnchor = ((UIAbstractContainer2)item).anchorInfo.OriginUIxAnchor;
                        anchorInfo.OriginUIyAnchor = ((UIAbstractContainer2)item).anchorInfo.OriginUIyAnchor;
                        ((UIAbstractContainer2)item).anchorInfo = anchorInfo;

                        // all items get their height added
                        _contentHeight += ((UIAbstractContainer2)item).height;

                        // width will just be the width of the widest item
                        if (_contentWidth < ((UIAbstractContainer2)item).width)
                        {
                            _contentWidth = ((UIAbstractContainer2)item).width;
                        }
                    }
                    else if (item as UISprite != null)
                    {
                        // we add spacing for all but the first and last
                        if (i != 0 && i != lastIndex)
                        {
                            _contentHeight += _spacing;
                        }

                        // Set anchor offset
                        anchorInfo.OffsetY = (_contentHeight + _scrollPosition) * hdFactor;
                        //anchorInfo.OffsetX = item.anchorInfo.OffsetX;

                        // dont overwrite the sprites origin anchor!
                        anchorInfo.OriginUIxAnchor  = ((UISprite)item).anchorInfo.OriginUIxAnchor;
                        anchorInfo.OriginUIyAnchor  = ((UISprite)item).anchorInfo.OriginUIyAnchor;
                        ((UISprite)item).anchorInfo = anchorInfo;

                        // all items get their height added
                        _contentHeight += ((UISprite)item).height;

                        // width will just be the width of the widest item
                        if (_contentWidth < ((UISprite)item).width)
                        {
                            _contentWidth = ((UISprite)item).width;
                        }
                    }
                    else if (item as UITextInstance != null)
                    {
                        // we add spacing for all but the first and last
                        if (i != 0 && i != lastIndex)
                        {
                            _contentHeight += _spacing;
                        }

                        // Set anchor offset
                        anchorInfo.OffsetY = (_contentHeight + _scrollPosition) * hdFactor;
                        //anchorInfo.OffsetX = item.anchorInfo.OffsetX;

                        // dont overwrite the sprites origin anchor!
                        anchorInfo.OriginUIxAnchor        = ((UITextInstance)item).anchorInfo.OriginUIxAnchor;
                        anchorInfo.OriginUIyAnchor        = ((UITextInstance)item).anchorInfo.OriginUIyAnchor;
                        ((UITextInstance)item).anchorInfo = anchorInfo;

                        // all items get their height added
                        _contentHeight += ((UITextInstance)item).height;

                        // width will just be the width of the widest item
                        if (_contentWidth < ((UITextInstance)item).width)
                        {
                            _contentWidth = ((UITextInstance)item).width;
                        }
                    }

                    i++;
                }
            }

            // add the right and bottom edge inset to finish things off
            _contentWidth  += _edgeInsets.right;
            _contentHeight += _edgeInsets.bottom;
        }
        else if (layoutType == UIAbstractContainerWrap.UILayoutType.AbsoluteLayout)
        {
            foreach (var item in _children)
            {
                if (item as UIAbstractContainer2 != null)
                {
                    UIAbstractContainer2 temp = (UIAbstractContainer2)item;
                    //temp.localPosition = new Vector3(temp.position.x, temp.position.y, temp.position.z);

                    // find the width that contains the item with the largest offset/width
                    if (_contentWidth < temp.localPosition.x + temp.width)
                    {
                        _contentWidth = temp.localPosition.x + temp.width;
                    }

                    // find the height that contains the item with the largest offset/height
                    if (_contentHeight < -temp.localPosition.y + temp.height)
                    {
                        _contentHeight = -temp.localPosition.y + temp.height;
                    }
                }
                else if (item as UISprite != null)
                {
                    UISprite temp = (UISprite)item;
                    //temp.localPosition = new Vector3(temp.position.x, temp.position.y, temp.position.z);

                    // find the width that contains the item with the largest offset/width
                    if (_contentWidth < temp.localPosition.x + temp.width)
                    {
                        _contentWidth = temp.localPosition.x + temp.width;
                    }

                    // find the height that contains the item with the largest offset/height
                    if (_contentHeight < -temp.localPosition.y + temp.height)
                    {
                        _contentHeight = -temp.localPosition.y + temp.height;
                    }
                }
                else if (item as UITextInstance != null)
                {
                    UITextInstance temp = (UITextInstance)item;
                    //temp.localPosition = new Vector3(temp.position.x, temp.position.y, temp.position.z);

                    // find the width that contains the item with the largest offset/width
                    if (_contentWidth < temp.localPosition.x + temp.width)
                    {
                        _contentWidth = temp.localPosition.x + temp.width;
                    }

                    // find the height that contains the item with the largest offset/height
                    if (_contentHeight < -temp.localPosition.y + temp.height)
                    {
                        _contentHeight = -temp.localPosition.y + temp.height;
                    }
                }
            }
        }

        // Refresh child position to proper positions
        foreach (var item in _children)
        {
            item.refreshPosition();
        }

        matchSizeToContentSize();
    }
    /// <summary>
    /// Responsible for laying out the child Layouts who will in turn
    /// layout their child sprites
    /// </summary>
    protected override void layoutChildren()
    {
        //Debug.Log("In UILayoutContainer's layoutChildren");
        if (_suspendUpdates)
        {
            return;
        }

        //var hdFactor = 1f / UI.scaleFactor;
        var anchorInfo = UIAnchorInfo.DefaultAnchorInfo();

        anchorInfo.ParentUIObject = this;
        var i         = 0;
        var lastIndex = _children.Count;

        _contentHeight = 0;
        foreach (var item in _children)
        {
            if (item as UIAbstractContainer2 != null)
            {
                // we add spacing for all but the first and last
                if (i != 0 && i != lastIndex)
                {
                    _contentHeight += _spacing;
                }
                else
                {
                    _contentHeight += myPadding;
                }

                item.localPosition = new Vector3(_edgeInsets.left, -(_contentHeight + _scrollPosition), item.localPosition.z);

                // all items get their height added
                _contentHeight += ((UIAbstractContainer2)item).contentHeight;

                // width will just be the width of the widest item
                if (_contentWidth < ((UIAbstractContainer2)item).contentWidth)
                {
                    _contentWidth = ((UIAbstractContainer2)item).contentWidth;
                }
            }
            else if (item as UISprite != null)
            {
                // we add spacing for all but the first and last
                if (i != 0 && i != lastIndex)
                {
                    _contentHeight += _spacing;
                }
                else
                {
                    _contentHeight += myPadding;
                }

                item.localPosition = new Vector3(_edgeInsets.left, -(_contentHeight + _scrollPosition), item.localPosition.z);

                // all items get their height added
                _contentHeight += ((UISprite)item).height;

                // width will just be the width of the widest item
                if (_contentWidth < ((UISprite)item).width)
                {
                    _contentWidth = ((UISprite)item).width;
                }

                /*
                 * if (i != 0 && i != lastIndex)
                 *  _contentHeight += _spacing;
                 *
                 * // Set anchor offset
                 * anchorInfo.OffsetY = (_contentHeight + _scrollPosition) * hdFactor;
                 * //anchorInfo.OffsetX = item.anchorInfo.OffsetX;
                 *
                 * // dont overwrite the sprites origin anchor!
                 * anchorInfo.OriginUIxAnchor = ((UISprite)item).anchorInfo.OriginUIxAnchor;
                 * anchorInfo.OriginUIyAnchor = ((UISprite)item).anchorInfo.OriginUIyAnchor;
                 * ((UISprite)item).anchorInfo = anchorInfo;
                 *
                 * // all items get their height added
                 * _contentHeight += ((UISprite)item).height;
                 *
                 * // width will just be the width of the widest item
                 * if (_contentWidth < ((UISprite)item).width)
                 *  _contentWidth = ((UISprite)item).width;*/
            }
            else if (item as UITextInstance != null)
            {
                // we add spacing for all but the first and last
                if (i != 0 && i != lastIndex)
                {
                    _contentHeight += _spacing;
                }
                else
                {
                    _contentHeight += myPadding;
                }

                item.localPosition = new Vector3(_edgeInsets.left, -(_contentHeight + _scrollPosition), item.localPosition.z);

                // all items get their height added
                _contentHeight += ((UITextInstance)item).height;

                // width will just be the width of the widest item
                if (_contentWidth < ((UITextInstance)item).width)
                {
                    _contentWidth = ((UITextInstance)item).width;
                }
            }

            i++;
        }

        // add the right and bottom edge inset to finish things off
        _contentWidth  += _edgeInsets.right;
        _contentHeight += _edgeInsets.bottom;

        //matchSizeToContentSize();
        clipToBounds();
    }