Exemple #1
0
    private void UpdateComponents(ScrollerLine line, float direction)
    {
        int nbPerLine = IsVertical ? _maxCount.x : _maxCount.y;
        int startIndex;

        if (direction > 0)
        {
            startIndex = (_targetLine * nbPerLine) + (_MaxCount * nbPerLine);
        }
        else
        {
            startIndex = _targetLine * nbPerLine;
        }
        int endIndex = startIndex + nbPerLine;
        int count    = 0;

        for (int i = startIndex; i < endIndex; i++)
        {
            if (count < line.components.Count)
            {
                if (i < ScrollerManager.GetDatas(_instanceID).Count)
                {
                    line.components[count].Init(ScrollerManager.GetDatas(_instanceID)[i]);
                    line.components[count].gameObject.SetActive(true);
                }
                else
                {
                    line.components[count].gameObject.SetActive(false);
                }
            }
            count++;
        }
    }
Exemple #2
0
    public void AddComponent(T comp, ScrollerData data)
    {
        ScrollerManager.AddComponent(_instanceID, data);
        _nbLineData  = 1 + (Mathf.CeilToInt(ScrollerManager.GetDatas(_instanceID).Count - 1) / (IsVertical ? _maxCount.x : _maxCount.y));
        _endPosition = (_nbLineData * _RefSize) - (_MaxCount * _RefSize);

        if (!IsFull)
        {
            if (container)
            {
                comp = Instantiate(comp, container);
            }
            else
            {
                comp = Instantiate(comp, RectTransform);
            }
            comp.Init(data);

            _listComponents.Add(comp);
            if (!_initialized)
            {
                Init();
            }
            if (_lines.Count < _nbLineData)
            {
                List <ScrollerComponent> nList = new List <ScrollerComponent>()
                {
                    comp
                };
                _lines.Add(new ScrollerLine()
                {
                    components = nList
                });
            }
            else
            {
                _lines[_nbLineData - 1].components.Add(comp);
            }
        }
        Refresh();
    }