Exemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        protected virtual void FillChildItemsList()
        {
            vChildItems.Clear();

            int childCount = transform.childCount;

            for (int i = 0; i < childCount; i++)
            {
                Transform       childTx = transform.GetChild(i);
                ILayoutableRect elem    = childTx.GetComponent <ILayoutableRect>();

                if (elem == null)
                {
                    //Debug.LogWarning("Item '"+childTx.name+"' does not have a renderer "+
                    //	"that implements '"+typeof(IRectangleLayoutElement).Name+"'.");
                    continue;
                }

                if (!elem.isActiveAndEnabled)
                {
                    continue;
                }

                var item = new HoverLayoutRectGroupChild(elem,
                                                         childTx.GetComponent <HoverLayoutRectRelativeSizer>());

                vChildItems.Add(item);
            }
        }
Exemplo n.º 2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        protected virtual void FillChildItemsList()
        {
            vChildItems.Clear();

            int childCount = transform.childCount;

            for (int i = 0; i < childCount; i++)
            {
                Transform       childTx = transform.GetChild(i);
                ILayoutableRect elem    = childTx.GetComponent <ILayoutableRect>();

                if (elem == null || !elem.isActiveAndEnabled)
                {
                    continue;
                }

                var item = new HoverLayoutRectGroupChild(elem,
                                                         childTx.GetComponent <HoverLayoutRectRelativeSizer>());

                vChildItems.Add(item);
            }
        }
Exemplo n.º 3
0
        /*--------------------------------------------------------------------------------------------*/
        private void UpdateLayoutWithFixedSize()
        {
            int itemCount = vChildItems.Count;

            if (itemCount == 0)
            {
                return;
            }

            bool    isHoriz       = IsHorizontal;
            bool    isRev         = IsReversed;
            Vector2 anchorPos     = RendererUtil.GetRelativeAnchorPosition(Anchor);
            float   anchorStartX  = anchorPos.x * SizeX;
            float   anchorStartY  = anchorPos.y * SizeY;
            float   horizOuterPad = Padding.Left + Padding.Right;
            float   vertOuterPad  = Padding.Top + Padding.Bottom;
            float   betweenSumPad = Padding.Between * (itemCount - 1);
            float   relSumX       = 0;
            float   relSumY       = 0;
            float   elemAvailSizeX;
            float   elemAvailSizeY;
            float   cellAvailSizeX;
            float   cellAvailSizeY;

            if (isHoriz)
            {
                elemAvailSizeX = SizeX - horizOuterPad - betweenSumPad;
                elemAvailSizeY = SizeY - vertOuterPad;
                cellAvailSizeX = SizeX - horizOuterPad;
                cellAvailSizeY = elemAvailSizeY;
            }
            else
            {
                elemAvailSizeX = SizeX - horizOuterPad;
                elemAvailSizeY = SizeY - vertOuterPad - betweenSumPad;
                cellAvailSizeX = elemAvailSizeX;
                cellAvailSizeY = SizeY - vertOuterPad;
            }

            for (int i = 0; i < itemCount; i++)
            {
                HoverLayoutRectGroupChild item = vChildItems[i];
                relSumX += item.RelativeSizeX;
                relSumY += item.RelativeSizeY;
            }

            float posX = anchorStartX - (Padding.Right - Padding.Left) / 2 -
                         (isHoriz ? cellAvailSizeX / 2 : 0);
            float posY = anchorStartY - (Padding.Top - Padding.Bottom) / 2 -
                         (isHoriz ? 0 : cellAvailSizeY / 2);

            for (int i = 0; i < itemCount; i++)
            {
                int childI = (isRev ? itemCount - i - 1 : i);
                HoverLayoutRectGroupChild item = vChildItems[childI];
                ILayoutableRect           elem = item.Elem;

                Vector3 localPos     = elem.transform.localPosition;
                float   elemRelSizeX = elemAvailSizeX * item.RelativeSizeX / (isHoriz ? relSumX : 1);
                float   elemRelSizeY = elemAvailSizeY * item.RelativeSizeY / (isHoriz ? 1 : relSumY);

                localPos.x = posX + (isHoriz ? elemRelSizeX / 2 : 0) +
                             elemRelSizeX * item.RelativePositionOffsetX;
                localPos.y = posY + (isHoriz ? 0 : elemRelSizeY / 2) +
                             elemRelSizeY * item.RelativePositionOffsetY;

                posX += (isHoriz ? elemRelSizeX + Padding.Between : 0);
                posY += (isHoriz ? 0 : elemRelSizeY + Padding.Between);

                elem.Controllers.Set(
                    SettingsControllerMap.SpecialPrefix + "Transform.localPosition.x", this);
                elem.Controllers.Set(
                    SettingsControllerMap.SpecialPrefix + "Transform.localPosition.y", this);

                elem.SetRectLayout(elemRelSizeX, elemRelSizeY, this);
                elem.transform.localPosition = localPos;
            }
        }