Пример #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        internal void Build(IHoverboardPanelState pPanelState, LayoutState pLayoutState,
                            IItemVisualSettingsProvider pItemVisualSettProv)
        {
            Vector2 dir    = pLayoutState.ItemLayout.Direction;
            Vector2 pos    = Vector2.zero;
            Vector2 posMin = Vector2.zero;
            Vector2 posMax = Vector2.zero;

            for (int i = 0; i < pLayoutState.FullItems.Length; i++)
            {
                BaseItemState       itemState  = pLayoutState.FullItems[i];
                IItemVisualSettings visualSett = pItemVisualSettProv.GetSettings(itemState.Item);
                GameObject          itemObj    = (GameObject)itemState.Item.DisplayContainer;

                UiItem uiItem = itemObj.AddComponent <UiItem>();
                uiItem.Build(pPanelState, pLayoutState, itemState, visualSett);
                uiItem.transform.localPosition = new Vector3(pos.x, 0, pos.y) * UiItem.Size;

                var itemSize = new Vector2(itemState.Item.Width, itemState.Item.Height);

                posMin = Vector2.Min(posMin, pos);
                posMax = Vector2.Max(posMax, pos + itemSize);
                pos   += Vector2.Scale(itemSize, dir);
            }

            Vector2 size = posMax - posMin;

            Bounds = new Rect(posMin.x, posMin.y, size.x, size.y);

            gameObject.transform.localPosition = Vector3.zero;
            gameObject.transform.localRotation = Quaternion.identity;
            gameObject.transform.localScale    = Vector3.one;
        }
Пример #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        internal void Build(GridState pGridState, IItemVisualSettingsProvider pItemVisualSettProv)
        {
            int cols = pGridState.ItemGrid.Cols;
            int gi   = 0;

            for (int i = 0; i < pGridState.Items.Length; i++)
            {
                BaseItemState       itemState  = pGridState.Items[i];
                IItemVisualSettings visualSett = pItemVisualSettProv.GetSettings(itemState.Item);
                GameObject          itemObj    = (GameObject)itemState.Item.DisplayContainer;
                var pos = new Vector3(gi % cols, 0, (float)Math.Floor((float)gi / cols));

                UiItem uiItem = itemObj.AddComponent <UiItem>();
                uiItem.Build(itemState, visualSett);
                uiItem.transform.localPosition = pos * UiItem.Size;

                gi += (int)itemState.Item.Width;
            }

            gameObject.transform.localPosition = Vector3.zero;
            gameObject.transform.localRotation = Quaternion.identity;
            gameObject.transform.localScale    = Vector3.one;
        }