示例#1
0
 // 选择高亮某个位置
 public void ShowGrid(OneGrid grid)
 {
     if (grid.gameObject.activeInHierarchy == false)
     {
         return;
     }
     if (currentOneGrid != null)
     {
         currentOneGrid.DeHighlightThis();
     }
     grid.HighlightThis();
     currentOneGrid = grid;
     ShowItemInfo(grid.pos.x, grid.pos.y);
 }
示例#2
0
        // 打开背包调用一次
        public void Show(Container box)
        {
            currentBox  = box;
            currentSize = new Vector2Int(xGrid, yGrid);
            grids       = new RectTransform[xGrid, yGrid];
            gridsText   = new Text[xGrid, yGrid];
            oneGrids    = new Dictionary <Vector2Int, OneGrid>();

            //int width = xGrid*gridSize + (xGrid+1)*gapSize;
            //int length = yGrid*gridSize + (yGrid+1)*gapSize;

            //int pageCount = Mathf.CeilToInt((float)box.GetAllItemsCount() / (float)(xGrid * yGrid));
            int pageCount = Mathf.CeilToInt((float)box.GridCount / (float)(xGrid * yGrid));


            tabsUICanvas = TabsUI.Instance.SetTabsUI(this, pageCount);

            for (int j = 0; j < yGrid; j++)
            {
                for (int i = 0; i < xGrid; i++)
                {
                    grids[i, j] = (Instantiate(uiGridPrefab, tabsUICanvas) as GameObject).GetComponent <RectTransform>();
                    // 偶数行X坐标不同
                    grids[i, j].anchoredPosition = new Vector2(j % 2 * evenLineDeltaX + (i + 1) * gapSize + i * gridSize + gridSize / 2, -(buttonSize + (j + 1) * gapSize + j * gridSize + gridSize / 2));

                    OneGrid one = grids[i, j].GetComponent <OneGrid>();
                    one.pos = new Vector2Int(i, j);
                    oneGrids.Add(new Vector2Int(i, j), one);

                    GameObject go = Instantiate(uiTextPrefab, grids[i, j]) as GameObject;
                    gridsText[i, j] = go.GetComponent <Text>();
                }
            }
            uiItemInfoText = Instantiate <GameObject>(uiItemInfoPrefab, tabsUICanvas).GetComponentInChildren <Text>();

            TabsUI.Instance.ShowPage(1);
            StartCoroutine(UpdatePage());
        }