Пример #1
0
        /// <summary>
        /// Recycles one cell view
        /// </summary>
        /// <param name="cellView"></param>
        private void _RecycleCell(EnhancedScrollerCellView cellView)
        {
            // remove the cell view from the active list
            _activeCellViews.Remove(cellView);

            // add the cell view to the recycled list
            _recycledCellViews.Add(cellView);

            // move the GameObject to the recycled container
            cellView.transform.SetParent(_recycledCellViewContainer, false);

            // reset the cellView's properties
            cellView.dataIndex = 0;
            cellView.cellIndex = 0;
            cellView.active = false;

            if (cellViewVisibilityChanged != null) cellViewVisibilityChanged(cellView);
        }
Пример #2
0
        /// <summary>
        /// Create a cell view, or recycle one if it already exists
        /// </summary>
        /// <param name="cellPrefab">The prefab to use to create the cell view</param>
        /// <returns></returns>
        public EnhancedScrollerCellView GetCellView(EnhancedScrollerCellView cellPrefab)
        {
            // see if there is a view to recycle
            var cellView = _GetRecycledCellView(cellPrefab);
            if (cellView == null)
            {
                cellView = _delegate.InstantiateCellView(this);

                if (cellView == null)
                {
                    // no recyleable cell found, so we create a new view
                    // and attach it to our container
                    var go = Instantiate(cellPrefab.gameObject);
                    cellView = go.GetComponent<EnhancedScrollerCellView>();
                }
                cellView.transform.SetParent(_container, false);
            }

            return cellView;
        }
Пример #3
0
        /// <summary>
        /// Get a recycled cell with a given identifier if available
        /// </summary>
        /// <param name="cellPrefab">The prefab to check for</param>
        /// <returns></returns>
        private EnhancedScrollerCellView _GetRecycledCellView(EnhancedScrollerCellView cellPrefab)
        {
            for (var i = 0; i < _recycledCellViews.Count; i++)
            {
                if (_recycledCellViews[i].cellIdentifier == cellPrefab.cellIdentifier)
                {
                    // the cell view was found, so we use this recycled one.
                    // we also remove it from the recycled list
                    var cellView = _recycledCellViews.RemoveAt(i);
                    return cellView;
                }
            }

            return null;
        }