Ejemplo n.º 1
0
        private void UpdateCells(int startIndex, int endIndex)
        {
            int length = _showGo.Count;

            for (int i = length - 1; i >= 0; i--)
            {
                ScrollCellItem item  = _showGo[i];
                int            index = item.GetIndex();
                if (index >= startIndex && index <= endIndex)
                {
                    continue;
                }

                _contains.Remove(index);
                Push(item);
                //Debug.Log("移除:" + index);
            }

            for (int i = startIndex; i <= endIndex; i++)
            {
                if (_contains.Contains(i))
                {
                    continue;
                }
                ScrollCellItem item = Pop();
                System.Object  data = _datas[i];
                item.SetPos(GetPos(i));
                item.SetData(data, i);
                _contains.Add(i);
                //Debug.Log("添加:" + i);
            }
        }
Ejemplo n.º 2
0
 private void Push(ScrollCellItem go)
 {
     _showGo.Remove(go);
     _hideGo.Add(go);
     go.transform.SetParent(_poolParent.transform);
     go.Clear();
 }
Ejemplo n.º 3
0
        private ScrollCellItem Create()
        {
            GameObject     unit = Instantiate(_prefabGo);
            ScrollCellItem item = unit.GetComponent <ScrollCellItem>();

            item.InitCreate();
            RectTransform rect = unit.GetComponent <RectTransform>();

            rect.pivot     = new Vector2(0.5f, 0.5f);
            rect.anchorMin = new Vector2(0.5f, 0.5f);
            rect.anchorMax = new Vector2(0.5f, 0.5f);
            return(item);
        }
Ejemplo n.º 4
0
        public void UpdateItemAt(int index, System.Object data)
        {
            _datas[index] = data;
            int length = _showGo.Count;

            for (int i = length - 1; i >= 0; i--)
            {
                ScrollCellItem item      = _showGo[i];
                int            showIndex = item.GetIndex();
                if (showIndex != index)
                {
                    continue;
                }
                item.SetData(data, index);
            }
        }
Ejemplo n.º 5
0
        private ScrollCellItem Pop()
        {
            ScrollCellItem reGo;

            if (_hideGo.Count > 0)
            {
                ScrollCellItem go = _hideGo[0];
                reGo = go;
                _showGo.Add(go);
                _hideGo.RemoveAt(0);
            }
            else
            {
                reGo = Create();
                _showGo.Add(reGo);
            }
            reGo.transform.SetParent(_containerParent.transform);
            return(reGo);
        }