コード例 #1
0
ファイル: SuperList.cs プロジェクト: ludidilu/Cook_client
        public void SetSelectedIndex(int _index)
        {
            if (selectedIndex == _index)
            {
                return;
            }

            if (needSelectedIndex)
            {
                for (int i = 0; i < showPool.Count; i++)
                {
                    SuperListCell cell = showPool[i];

                    if (cell.index == _index)
                    {
                        cell.SetSelected(true);
                    }
                    else if (cell.index == selectedIndex)
                    {
                        cell.SetSelected(false);
                    }
                }

                selectedIndex = _index;
            }

            if (selectedIndex != -1 || !needSelectedIndex)
            {
                if (CellClickHandle != null)
                {
                    CellClickHandle(data[_index]);
                }

                if (CellClickIndexHandle != null)
                {
                    CellClickIndexHandle(_index);
                }
            }
        }
コード例 #2
0
ファイル: SuperList.cs プロジェクト: ludidilu/Cook_client
        private void SetCellIndex(SuperListCell _cell, int _index)
        {
            int row;

            int col;

            float xFix = 0;

            float yFix = 0;

            if (isVertical)
            {
                row = _index / colNum;

                col = _index % colNum;

                if (insertIndexArr != null)
                {
                    for (int i = 0; i < insertIndexArr.Length; i++)
                    {
                        if (row >= insertIndexArr[i])
                        {
                            yFix += insertRectArr[i].rect.height + verticalGap;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                col = _index / rowNum;

                row = _index % rowNum;

                if (insertIndexArr != null)
                {
                    for (int i = 0; i < insertIndexArr.Length; i++)
                    {
                        if (col >= insertIndexArr[i])
                        {
                            xFix += insertRectArr[i].rect.width + horizontalGap;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }

            float xPos = col * (cellWidth + horizontalGap) + xFix;

            float yPos = -row * (cellHeight + verticalGap) - yFix;

            Vector2 pos = new Vector2(xPos, yPos);

            (_cell.transform as RectTransform).anchoredPosition = pos;

            _cell.index = _index;

            //_cell.gameObject.name = unitName + _index;

            _cell.SetSelected(_index == selectedIndex);//如果补全空的单元格  这里可能会有问题
        }