// Basic example 1, oscillating characters and color private void Tween1(int start, int end) { for (var i = start; i <= end; ++i) { var timeOffset = Mathf.Lerp(0, 1, (i - start) / (float)(end - start + 1)); var circleTween = _tweener.DOCircle(i, radius, 0.5f) .SetEase(Ease.Linear) .SetLoops(-1, LoopType.Restart); var colorTween = _tweener.DOColor(i, Color.yellow, 0.5f) .SetLoops(-1, LoopType.Yoyo); circleTween.fullPosition = timeOffset; colorTween.fullPosition = timeOffset; } }
void Start() { // Set text TMP_Text textMesh = GetComponent <TMP_Text>(); textMesh.text = "DETERMINATION"; CharTweener tweener = textMesh.GetCharTweener(); for (int i = 0; i < tweener.CharacterCount; i++) { // Move characters in a circle Tween circleTween = tweener.DOMoveCircle(i, 0.05f, 0.5f) .SetLoops(-1, LoopType.Restart); // Fade character color between yellow and white Tween colorTween = tweener.DOColor(i, Color.yellow, 0.5f) .SetLoops(-1, LoopType.Yoyo); // Offset animations based on character index in string float timeOffset = (float)i / tweener.CharacterCount; circleTween.fullPosition = timeOffset; colorTween.fullPosition = timeOffset; } }
public void UpdatePrompt(StoryText text, Action <int> callback, string characterIndex = "") { textMeshPro.gameObject.SetActive(true); button.enabled = true; textMeshPro.text = text.ProcessText(); SetTextSettings(text); if (GameState.Instance.characters.ContainsKey(characterIndex)) { Character target = GameState.Instance.characters[characterIndex]; GetComponent <InfoView>().SetInfo(target); } List <Color> ColorMapping = text.MapColor(attributesLookup); CharTweener _tweener = textMeshPro.GetCharTweener(); var sequence = DOTween.Sequence(); for (var i = 0; i < textMeshPro.text.Length; i++) { _tweener.DOColor(i, ColorMapping[i], 0.1f); } ActivateButton(text.settings, callback); }
// Reset state between runs so we don't have random colors from last call everywhere private Tween[] GetResetTweens(CharTweener charTweener) { Tween[] resets = new Tween[text.text.Length]; for (int i = 0; i < text.text.Length; i++) { resets[i] = DOTween.Sequence() .Append(charTweener.DOColor(i, Color.white, 0)) .Append(charTweener.DOCircle(i, 0, 0)); } return(resets); }
private Sequence AnimatePerCharacter(StoryText text, Action <int> callback, string characterIndex = "") { textMeshPro.color = Color.clear; textMeshPro.text = text.ProcessText(); List <Color> ColorMapping = text.MapColor(attributesLookup); CharTweener _tweener = textMeshPro.GetCharTweener(); SetTextSettings(text); SoundEffectProfile textBlip = defaultTextTic; if (characterIndex != "") { textBlip = attributesLookup.GetCharacterAttributes(characterIndex).soundPing; } var sequence = DOTween.Sequence(); for (var i = 0; i < textMeshPro.text.Length; i++) { var timeOffset = Mathf.Lerp(0, 1, i / (float)(textMeshPro.text.Length + 1)); var charSequence = DOTween.Sequence(); if ((i % 2 == 0 && textMeshPro.text.Length < 20) || i % 4 == 0) { charSequence.AppendCallback(() => textBlip?.Play()); } charSequence.Join(_tweener.DOColor(i, ColorMapping[i], 0.01f)) .Join(_tweener.DOScale(i, 0, 0.01f).From()); if (i == textMeshPro.text.Length - 1) { charSequence.AppendInterval(0.1f) .AppendCallback(() => { ActivateButton(text.settings, callback); }); } sequence.Insert(timeOffset * text.settings.speed, charSequence); } return(sequence); }
private void Error(TMP_Text text, int?charsAhead = null) { Sequence textSequence = DOTween.Sequence(); CharTweener tweener = text.GetCharTweener(); DOTween.Kill(tweener, complete: true); int count = charsAhead ?? tweener.CharacterCount; for (int i = 0; i < count; i++) { Sequence charSequence = DOTween.Sequence(); Color oldColor = tweener.GetColor(i); tweener.SetColor(i, Color.red); charSequence.Insert(0, tweener.DOColor(i, oldColor, 0.5f).SetTarget(tweener)); charSequence.Insert(0, tweener.DOShakeRotation(i, 0.5f, Vector3.forward * 25, 20).SetTarget(tweener)); textSequence.Insert((float)i / count * 0.25f, charSequence); } textSequence.SetId(errorId); }
private Sequence AnimatePerWord(StoryText text, Action <int> callback) { textMeshPro.text = text.ProcessText(); List <Color> ColorMapping = text.MapColor(attributesLookup); CharTweener _tweener = textMeshPro.GetCharTweener(); SoundEffectProfile textBlip = defaultTextTic; textMeshPro.color = Color.clear; var sequence = DOTween.Sequence(); sequence.AppendInterval(text.settings.speed); int i = 0; while (i < textMeshPro.text.Length) { int j = i; sequence.AppendCallback(() => textBlip?.Play()); while (j < textMeshPro.text.Length - 1 && textMeshPro.text[j] != ' ') { sequence.Join(_tweener.DOColor(j, ColorMapping[j], 0.01f)) .Join(_tweener.DOScale(j, 0, 0.01f).From()); j++; } sequence.AppendInterval(text.settings.speed); i = j; i++; } sequence.AppendInterval(0.1f) .AppendCallback(() => { ActivateButton(text.settings, callback); }); return(sequence); }