Exemplo n.º 1
0
            public void Update(IList <T> items, float deltaTime)
            {
                FindChanges(items, out _, out List <ScrollListItem> toRemove);

                //Fade out and destroy old ones
                foreach (ScrollListItem item in toRemove)
                {
                    item._lerp  = 1.0f;
                    item._state = ScrollListItem.State.FadingOut;
                    item._item.OnHide();
                    _itemsBeingRemoved.Add(item);
                }

                UpdateOrdering();
                UpdateContentSize();

                //Lerp items to their target positions, lerp fade in
                foreach (ScrollListItem item in _items)
                {
                    if (item._lerp < 1.0f)
                    {
                        item._lerp = Mathf.Clamp01(item._lerp + _lerpSpeed * deltaTime);

                        if (item._state == ScrollListItem.State.Moving)
                        {
                            float curvedLerp = MovementCurve.Evaluate(item._lerp);
                            item._item.GetTransform().anchoredPosition = Vector2.Lerp(item._fromPosition, item._targetPosition, curvedLerp);
                        }
                        else if (item._state == ScrollListItem.State.FadingIn)
                        {
                            item._item.SetFade(item._lerp);
                        }

                        if (item._lerp >= 1.0f)
                        {
                            item._state = ScrollListItem.State.Normal;
                        }
                    }
                }

                //Lerp fade out for items being removed, destroy any that are no zero
                for (int i = 0; i < _itemsBeingRemoved.Count;)
                {
                    _itemsBeingRemoved[i]._lerp += _lerpSpeed * deltaTime;

                    if (_itemsBeingRemoved[i]._lerp > 1.0f)
                    {
                        _itemPool.Destroy(_itemsBeingRemoved[i]._item.GetTransform().gameObject);
                        _itemsBeingRemoved.RemoveAt(i);
                    }
                    else
                    {
                        _itemsBeingRemoved[i]._item.SetFade(1.0f - _itemsBeingRemoved[i]._lerp);
                        i++;
                    }
                }
            }
Exemplo n.º 2
0
 public void Destroy()
 {
     _parentPool.Destroy(this.gameObject);
 }
Exemplo n.º 3
0
                private void UpdateLines(float deltaTime)
                {
                    //keep lines in sync
                    TMP_TextInfo textInfo   = _textMesh.textInfo;
                    float        lineHeight = _lineHeight * _textMesh.fontSize;

                    //Need to add new lines
                    if (_lines.Length < textInfo.lineCount)
                    {
                        Image[] lines = new Image[textInfo.lineCount];

                        for (int i = 0; i < lines.Length; i++)
                        {
                            if (i < _lines.Length)
                            {
                                lines[i] = _lines[i];
                            }
                            else
                            {
                                lines[i] = _linePrefabPool.Instantiate(_textMesh.rectTransform).GetComponent <Image>();
                                lines[i].rectTransform.pivot     = new Vector2(0f, 0.5f);
                                lines[i].rectTransform.anchorMin = new Vector2(0f, 0f);
                                lines[i].rectTransform.anchorMax = new Vector2(0f, 0f);
                                lines[i].rectTransform.sizeDelta = new Vector2(0f, lineHeight);
                            }
                        }

                        _lines = lines;

                        if (!_animated)
                        {
                            _lineIndex = textInfo.lineCount;
                        }
                    }
                    //Need to remove lines
                    else if (_lines.Length > textInfo.lineCount)
                    {
                        Image[] lines = new Image[textInfo.lineCount];

                        for (int i = 0; i < _lines.Length; i++)
                        {
                            if (i < textInfo.lineCount)
                            {
                                lines[i] = _lines[i];
                            }
                            else
                            {
                                _linePrefabPool.Destroy(_lines[i].gameObject);
                            }
                        }

                        _lines = lines;

                        if (_lineIndex > textInfo.lineCount)
                        {
                            _lineIndex        = textInfo.lineCount;
                            _currentLineSpeed = _speed;
                        }
                    }

                    //Update animations
                    if (_animated && _lineIndex < _lines.Length && deltaTime > 0f)
                    {
                        RectTransform currentLine = _lines[_lineIndex].rectTransform;
                        currentLine.anchoredPosition = GetLinePosition(textInfo.lineInfo[_lineIndex], out float lineWidth);

                        float currentWidth = RectTransformUtils.GetWidth(currentLine);

                        if (currentWidth < lineWidth)
                        {
                            _currentLineSpeed += _acceleration * deltaTime;
                            currentWidth      += _currentLineSpeed * deltaTime;

                            if (currentWidth >= lineWidth)
                            {
                                currentWidth           = lineWidth;
                                _currentLinePauseTimer = _endOfLinePause;
                            }
                        }
                        else
                        {
                            currentWidth            = lineWidth;
                            _currentLinePauseTimer -= deltaTime;

                            if (_currentLinePauseTimer <= 0f)
                            {
                                _currentLineSpeed = _speed;
                                _lineIndex++;
                            }
                        }

                        currentLine.sizeDelta = new Vector2(currentWidth, lineHeight);
                    }

                    //Update shown lines
                    for (int i = 0; i < Mathf.Min(_lines.Length, _lineIndex); i++)
                    {
                        _lines[i].rectTransform.anchoredPosition = GetLinePosition(textInfo.lineInfo[i], out float lineWidth);
                        _lines[i].rectTransform.sizeDelta        = new Vector2(lineWidth, lineHeight);
                        _lines[i].color = _lineColor;
                    }
                }