The Text Typewriter Effect Use Colors(NGUI打字效果加上颜色)
2013-07-12 14:39
477 查看
using UnityEngine; /// <summary> /// Trivial script that fills the label's contents gradually, as if someone was typing. /// </summary> [RequireComponent(typeof(UILabel))] [AddComponentMenu("NGUI/Examples/Typewriter Effect")] public class TypewriterEffect : MonoBehaviour { public int charsPerSecond = 40; public AudioClip typeSound; UILabel mLabel; string mText; int mOffset = 0; float mNextChar = 0f; void OnEnable(){ mLabel = GetComponent<UILabel>(); mLabel.enabled = false; mLabel = null; } void Start(){ } public void FinishTypewriter(){ mLabel.text = mText; Destroy(this); } void Update () { if (mLabel == null) { mLabel = GetComponent<UILabel>(); //mLabel.supportEncoding = false; mLabel.enabled = true; mLabel.symbolStyle = UIFont.SymbolStyle.None; mText = mLabel.font.WrapText(mLabel.text, mLabel.lineWidth / mLabel.cachedTransform.localScale.x, mLabel.maxLineCount, true, UIFont.SymbolStyle.None); } if (mOffset < mText.Length) { if (mNextChar <= Time.time) { charsPerSecond = Mathf.Max(1, charsPerSecond); // Periods and end-of-line characters should pause for a longer time. float delay = 1f / charsPerSecond; char c = mText[mOffset]; if (c == '.' || c == ',' || c == '!' || c == '?' || c == ' ') delay *= 4f; else if (c == '。' || c == '?' || c == '!' || c == ',' ) delay *= 4f; string s = mText.Substring(0, ++mOffset); if(c == '['){ for(int i = 0;i< 20; i++){ s = mText.Substring(0, ++mOffset); int index2 = s.IndexOf(']',mOffset - 1); if(index2 != -1 ){ break; } } } else if(c == '\\'){ s = mText.Substring(0, ++mOffset); } mLabel.text = s; if(typeSound != null){ AudioManage.Instance.PlayOneShot(typeSound); } mNextChar = Time.time + delay; } } else Destroy(this); } }
相关文章推荐
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- NGUI的打字效果typewirter Effect
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- NGUI中打字效果TypewriterEffect的一个BUG
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- Node“getTextContent() is undefined for the type Node”处理办法
- TextView点击之后出现文字颜色更换效果,之后又马上变回原来
- Android TextView的点击效果之改变背景颜色
- 项目报错:The method getTextContent() is undefined for the type Node
- 文本颜色和效果——text-decoration
- The username you provided is not allowed to use the text-based Tomcat Manager (error 403)