private void UpdateChildren(float movementTime)
            {
                float xPos = GetInitalX();

                List <GameObject> activeChildren = new List <GameObject>();

                foreach (RectTransform child in this.transform)
                {
                    if (child != null && child.gameObject.activeSelf)
                    {
                        if (!_childMovers.TryGetValue(child, out RectTransformMover mover) || mover == null)
                        {
                            mover = child.GetComponent <RectTransformMover>();
                            _childMovers.Add(child, mover);
                        }

                        activeChildren.Add(child.gameObject);

                        if (mover != null)
                        {
                            bool wasActive = _activeChildren.Contains(child.gameObject);
                            mover.SetX(xPos, wasActive ? movementTime : -1f, _movementInterpolationType);
                        }
                        else
                        {
                            RectTransformUtils.SetX(child, xPos);
                        }

                        xPos += RectTransformUtils.GetWidth(child) + _spacing;
                    }
                }

                _activeChildren = activeChildren;
            }
            public float GetContentWidth()
            {
                float width = 0f;

                bool first = true;

                foreach (RectTransform child in this.transform)
                {
                    if (child != null && child.gameObject.activeSelf)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            width += _spacing;
                        }

                        width += RectTransformUtils.GetWidth(child);
                    }
                }

                return(width);
            }
            private void UpdateChildrenInEditMode()
            {
                float xPos = GetInitalX();

                foreach (RectTransform child in this.transform)
                {
                    if (child.gameObject.activeSelf)
                    {
                        RectTransformUtils.SetX(child, xPos);
                        xPos += RectTransformUtils.GetWidth(child) + _spacing;
                    }
                }
            }
            private float GetContentWidth()
            {
                float width = 0f;

                foreach (RectTransform child in this.transform)
                {
                    if (child != null && child.gameObject.activeSelf)
                    {
                        width += RectTransformUtils.GetWidth(child) + _spacing;
                    }
                }

                return(width - _spacing);
            }
Example #5
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;
                    }
                }