Ejemplo n.º 1
0
        public void UpdateGraphics(float viewportSize, float contentSize, float scrollOffset, float scrollSize, float interval)
        {
            float kLines = m_secondaryLinesCount;

            float size = contentSize;

            size /= interval;

            float s1 = Mathf.Pow(kLines, Mathf.Ceil(Mathf.Log(interval * scrollSize, kLines)));
            float s0 = Mathf.Pow(kLines, Mathf.Ceil(Mathf.Log(interval * scrollSize, kLines)) - 1);

            size *= s1;

            m_textRoot.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size);
            LayoutRebuilder.ForceRebuildLayoutImmediate(m_textRoot);

            Vector2 position = m_textRoot.anchoredPosition;
            float   mod      = (((contentSize / m_linesCount) / interval) * s1);

            position.x = -((contentSize - viewportSize) * scrollOffset) % mod;
            m_textRoot.anchoredPosition = position;

            float seconarySpace = size / m_textList.Count;
            float primarySpace  = seconarySpace * m_secondaryLinesCount;

            float roundTo = Mathf.Pow(kLines, Mathf.Floor(Mathf.Log(s1, kLines)));
            float offset  = Mathf.FloorToInt(m_linesCount * interval * (1 - scrollSize) * scrollOffset / roundTo) * roundTo;

            const int maxDigits = 5;

            int maxIntervalDigits = Mathf.RoundToInt(MathHelper.CountOfDigits(Mathf.CeilToInt(m_linesCount * interval / m_samples)));
            int sampleDigits      = Mathf.RoundToInt(MathHelper.CountOfDigits(m_samples));

            string intervalFormat = "0";
            string sampleFormat   = "1:D" + sampleDigits;

            string format;

            if (maxDigits - maxIntervalDigits >= sampleDigits)
            {
                format = "{" + intervalFormat + "}:{" + sampleFormat + "}";
            }
            else
            {
                format = "{" + intervalFormat + "}";
            }

            for (int i = 0; i < m_textList.Count; ++i)
            {
                TimelineText text = m_textList[i];
                text.ForceMeshUpdate();
            }

            int pad = Mathf.Max(maxIntervalDigits, maxDigits + 1);

            for (int i = 0; i < m_textList.Count; ++i)
            {
                TimelineText text = m_textList[i];

                int t = Mathf.RoundToInt(offset + i * s0);
                int intervalNumber = t / m_samples;
                int sampleNumber   = t % m_samples;

                text.Text = string.Format(format, intervalNumber, sampleNumber).PadRight(pad, ' ');

                text.Refresh(primarySpace, seconarySpace);
            }
        }