Example #1
0
        /// <summary>
        /// 排序
        /// </summary>
        /// <param name="size">视口尺寸</param>
        /// <param name="pos">视口位置</param>
        public void Order(bool force = false)
        {
            float w = Size.x;
            float h = Size.y;

            int colStart = (int)(_pos.x / ItemActualSize.x);

            if (colStart < 0)
            {
                colStart = 0;
            }
            int rowStart = (int)(_pos.y / ItemActualSize.y);

            if (rowStart < 0)
            {
                rowStart = 0;
            }
            int rc = (int)(h / ItemActualSize.y) + 1;
            int cc = (int)(w / ItemActualSize.x) + 1;

            if (scrollType != ScrollType.Loop)
            {
                if (cc + colStart > Column)
                {
                    cc = Column - colStart;
                }
                if (rc + rowStart > Row)
                {
                    rc = Row - rowStart;
                }
            }

            Recycler.AddRange(Items);
            Items.Clear();
            for (int i = 0; i < rc; i++)
            {
                int index = (rowStart + i) * Column + colStart;
                int cou   = DataLength;
                for (int j = 0; j < cc; j++)
                {
                    if (index >= cou)
                    {
                        break;
                    }
                    for (int k = 0; k < Recycler.Count; k++)
                    {
                        var t = Recycler[k];
                        if (t.index == index)
                        {
                            Items.Add(t);
                            Recycler.RemoveAt(k);
                            t.target.activeSelf = true;
                            break;
                        }
                    }
                    index++;
                }
            }
            float oy = 0;

            for (int i = 0; i < rc; i++)
            {
                UpdateRow(rowStart, colStart, cc, force, oy);
                rowStart++;
                if (rowStart >= Row)
                {
                    rowStart = 0;
                    oy       = _contentSize.y;
                }
            }
            for (int i = 0; i < Recycler.Count; i++)
            {
                Recycler[i].target.activeSelf = false;
            }
        }