예제 #1
0
        public void Init(TextControl textControl, TextPage textPage)
        {
            _textControl = textControl;
            _textPage    = textPage;

            _animators.Clear();
        }
예제 #2
0
        public override void Init(TextControl textControl, TextPage page)
        {
            base.Init(textControl, page);

            SetCharsStartPositions(textControl, page);

            SetOffset(textControl, page);
        }
예제 #3
0
        private void SetOffset(TextControl textControl, TextPage page)
        {
            var dir = GetStartOffsetDir(page.CharByCharInfo.OffsetType, page.CharByCharInfo.Offset);

            _offsetToMoveBack = -dir;

            //i have to find a way to offset the chars individually and not moving the entire rectTransform.
            textControl.OffsetText(dir);
        }
예제 #4
0
        private void SetCharsStartPositions(TextControl textControl, TextPage page)
        {
            _startPos.Clear();

            for (int i = 0; i < page.Text.Length; i++)
            {
                _startPos.Add(textControl.GetCharPos(i));
            }
        }
예제 #5
0
        public void Init(int pagesCount)
        {
            _pagesCount = pagesCount;

            if (_texControl == null)
            {
                _texControl = new TextControl(_text);
            }

            Clear();
        }
예제 #6
0
        public override void Update()
        {
            for (int i = 0; i < CharsToAnimateCount; i++)
            {
                var index = GetValidCharToAnimate(i);

                var targetPos = TextControl.OffsetVectors(_startPos[index], _offsetToMoveBack);

                TextControl.SetCharPos(index, TextControl.LerpCharPos(TextControl.GetCharPos(index), targetPos, 30 * Time.deltaTime));
            }
        }
예제 #7
0
 public override void Update()
 {
     if (CharsToAnimateCount > 0)
     {
         for (int i = 0; i < CharsToAnimateCount; i++)
         {
             //this needs work, is not very consistent.
             TextControl.OffsetChar(GetValidCharToAnimate(i), new Vector2(0, Mathf.Sin(i + Time.time * _freq) * _amp));
         }
     }
 }
예제 #8
0
        public WriterBase GetWriter(WriteType writerType, TextControl textControl)
        {
            var writer = default(WriterBase);

            switch (writerType)
            {
            case WriteType.Instant:
                writer = _writers[typeof(InstantWriter)];
                break;

            case WriteType.CharByChar:
                writer = _writers[typeof(CharByCharWriter)];
                break;

            default:
                Debug.LogError($"Type: {writerType} is not in the factory.");
                return(null);
            }

            writer.SetTextControl(textControl);

            return(writer);
        }
예제 #9
0
        protected override IEnumerator Write(TextControl control, TextPage page, TextAnimationControl animationControl)
        {
            var wordIndex        = 0;
            var whiteSpacesCount = -1;
            var highlightedWord  = -1;

            for (int i = 0; i < page.Text.Length; i++)
            {
                if (highlightedWord != wordIndex && page.Highlight.ContainsKey(wordIndex))
                {
                    highlightedWord = wordIndex;

                    var highlight       = page.Highlight[wordIndex];
                    var highlightLength = highlight.HighlighLength;
                    var startChar       = highlight.StartLocalChar;


                    var prevWriteSpeed = WriteSpeedType;

                    //Set default color to chars not colored by the highlight color.
                    for (int j = 0; j < startChar; j++)
                    {
                        var charIndex = i + j;

                        control.ShowChar(charIndex);
                    }

                    i += startChar;

                    for (int j = 0; j < highlightLength; j++)
                    {
                        var charIndex = i + j;

                        control.ShowChar(charIndex, highlight.Color);
                        animationControl.HighlightedChar(charIndex, highlight);

                        yield return(WriteSpeed);

                        if (highlight.WriteSpeedType == Highlight.HighlightWriteSpeed.Default || WriteSpeedType == WriteSpeedType.Fast)
                        {
                            yield return(WriteSpeed);

                            prevWriteSpeed = WriteSpeedType;

                            continue;
                        }
                        else if (!_hightlightWriteSpeed)
                        {
                            _hightlightWriteSpeed = true;

                            WriteSpeed = new WaitForSeconds(highlight.NormalWriteSpeed);
                        }

                        if (highlight.WriteSpeedType == Highlight.HighlightWriteSpeed.Custom)
                        {
                            yield return(WriteSpeed);
                        }
                    }

                    SetWriteTypeSpeed(prevWriteSpeed);
                    _hightlightWriteSpeed = false;

                    var target = i + highlightLength;

                    //When it could be possible to write normal chars in a highlighted word
                    while (page.Text.ElementAtOrDefault(i).IsValidChar())
                    {
                        if (i >= target)
                        {
                            control.ShowChar(i);
                            animationControl.NormalChar(i);

                            if (WriteSpeedType == WriteSpeedType.Normal || WriteSpeedType == WriteSpeedType.Fast && page.CharByCharInfo.FastWriteSpeed > 0)
                            {
                                yield return(WriteSpeed);
                            }
                        }

                        i++;

                        whiteSpacesCount = 0;
                    }
                }
                else
                {
                    //When is not in highlight
                    while (page.Text.ElementAtOrDefault(i).IsValidChar())
                    {
                        control.ShowChar(i);
                        animationControl.NormalChar(i);

                        if (WriteSpeedType == WriteSpeedType.Normal || WriteSpeedType == WriteSpeedType.Fast && page.CharByCharInfo.FastWriteSpeed > 0)
                        {
                            yield return(WriteSpeed);
                        }

                        i++;
                    }

                    //Only if the next char is the start of a word.
                    if (page.Text.ElementAtOrDefault(i + 1).IsValidChar())
                    {
                        whiteSpacesCount = 0;
                    }
                }

                whiteSpacesCount++;

                if (whiteSpacesCount == 1)
                {
                    wordIndex++;
                }
            }

            OnPageWritten?.Invoke();
        }
예제 #10
0
 public void Init(TextPage page, TextControl textControl)
 {
     _writer = _writersFactory.GetWriter(page.WriteType, textControl);
 }
예제 #11
0
 public virtual void Init(TextControl textControl, TextPage page)
 {
     _textControl = textControl;
     _textPage    = page;
     _charIndexesToAnimate.Clear();
 }