Exemple #1
0
        void UpdateCellPosition <T>(IScrollableCell <T> cell, T data, List <T> dataList, int mainPivotVectorValue, int subPivotVectorValue, float baseCellPosition)
        {
            int dataIndex = dataList.IndexOf(data);

            cell.transform.localPosition =
                CreateScrollTypeVector(
                    _scrollType,
                    Mathf.CeilToInt(dataIndex / _columnLimit) * baseCellPosition + GetScrollTypeValue(_scrollType, _cellSize) * 0.5f * mainPivotVectorValue,
                    dataIndex % _columnLimit * GetNonScrollTypeValue(_scrollType, _cellSize) * subPivotVectorValue + GetNonScrollTypeValue(_scrollType, _cellSize) * 0.5f * subPivotVectorValue);
        }
Exemple #2
0
        static List <IScrollableCell <T> > CreateCellList <T>(int cellNum, GameObject cellPrefab, List <T> dataList, Transform cellRoot)
        {
            List <IScrollableCell <T> > result = new List <IScrollableCell <T> >();

            for (int i = 0; i < cellNum; i++)
            {
                if (i >= dataList.Count)
                {
                    continue;
                }
                IScrollableCell <T> cell = GameObject.Instantiate(cellPrefab).GetComponent <IScrollableCell <T> >();
                cell.SetValue(dataList[i]);
                Transform cellTransform = cell.transform;
                cellTransform.SetParent(cellRoot);
                cellTransform.localScale = Vector3.one;
                cellTransform.rotation   = cellRoot.rotation;
                result.Add(cell);
            }
            return(result);
        }
Exemple #3
0
        List <IScrollableCell <T> > GenerateCellList <T>(GameObject cellPrefab, List <T> dataList, Transform cellRoot, out IDisposable cellDisposable)
        {
            DisposableBundle disposable = new DisposableBundle();
            var rootTransform           = GetComponent <RectTransform>();
            int cellNum = 0;

            switch (_scrollType)
            {
            case ScrollType.Horizontal:
                cellNum = (Mathf.CeilToInt(rootTransform.rect.width / _cellSize.x) + 1) * _columnLimit;
                break;

            case ScrollType.Vertical:
                cellNum = (Mathf.CeilToInt(rootTransform.rect.height / _cellSize.y) + 1) * _columnLimit;
                break;
            }

            List <IScrollableCell <T> > result = new List <IScrollableCell <T> >();

            for (int i = 0; i < cellNum; i++)
            {
                if (i >= dataList.Count)
                {
                    continue;
                }
                var cellObject           = GameObject.Instantiate(cellPrefab);
                IScrollableCell <T> cell = cellObject.GetComponent <IScrollableCell <T> >();
                cell.SetValue(dataList[i]);
                Transform cellTransform = cell.transform;
                cellTransform.SetParent(cellRoot);
                cellTransform.localScale = Vector3.one;
                cellTransform.rotation   = cellRoot.rotation;
                result.Add(cell);
                disposable.Add(new GameObjectDisposable(cellObject));
            }
            cellDisposable = disposable;
            return(result);
        }