Created
November 6, 2017 15:40
-
-
Save lycoris102/fcf2dd7376aec4b923662fddc10dcaa6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using DG.Tweening; | |
using UnityEngine; | |
using UnityEngine.UI; | |
// see also : http://dotween.demigiant.com/documentation.php | |
public class DOTextSample : MonoBehaviour | |
{ | |
public Text Text; | |
public Button Button; | |
public List<string> TextList; | |
private Tween animationTween; | |
private int index = 0; | |
void Start() | |
{ | |
if (this.TextList.Count == 0) return; | |
this.animationTween = this.CreateAnimationTween(this.TextList[index]); | |
this.animationTween.Play(); | |
this.Button.onClick.AddListener(() => | |
{ | |
if (this.animationTween.IsPlaying()) | |
{ | |
this.animationTween.Complete(); | |
} | |
else if (index < this.TextList.Count) | |
{ | |
this.Text.text = ""; | |
this.animationTween = this.CreateAnimationTween(this.TextList[index]); | |
this.animationTween.Play(); | |
} | |
else | |
{ | |
Debug.Log("completed"); | |
} | |
}); | |
} | |
Tween CreateAnimationTween(string text) | |
{ | |
float duration = this.CalcDuration(text); | |
return this.animationTween = this.Text.DOText(text, duration) | |
.OnComplete(() => this.index++) | |
.SetEase(Ease.Linear); | |
} | |
float CalcDuration(string text) | |
{ | |
return text.Length * 0.1f; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment