UGUI简易Typewriter
来源:互联网 发布:oracle sql 语法大全 编辑:程序博客网 时间:2024/05/24 06:05
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using System.Text;
[RequireComponent(typeof(Text))]
public class TypeWriter : MonoBehaviour {
public float waitTime = 0.05f;
StringBuilder sb = new StringBuilder();
Text text;
private float currentCount;
private float totalCount;
private string str = "";
void Start()
{
text = this.GetComponent<Text>();
str = text.text;
currentCount = 0;
totalCount = text.text.Length;
StartCoroutine(ShowText());
}
/// <summary>
/// 显示文本
/// </summary>
/// <returns></returns>
IEnumerator ShowText()
{
while (true)
{
currentCount++;
if (currentCount > totalCount)
{
yield break;
}
else
{
sb.Remove(0, sb.Length);
for (int i = 0; i < currentCount; i++)
{
sb.Append(str[i]);
}
text.text = sb.ToString();
yield return new WaitForSeconds(waitTime);
}
}
}
/// <summary>
/// 重置文本
/// </summary>
/// <param name="mText"></param>
public void ResetText(string mText)
{
StopAllCoroutines();
str = mText;
currentCount = 0;
totalCount = mText.Length;
StartCoroutine(ShowText());
}
void OnDestory()
{
sb = null;
}
}
using UnityEngine;
using UnityEngine.UI;
using System.Text;
[RequireComponent(typeof(Text))]
public class TypeWriter : MonoBehaviour {
public float waitTime = 0.05f;
StringBuilder sb = new StringBuilder();
Text text;
private float currentCount;
private float totalCount;
private string str = "";
void Start()
{
text = this.GetComponent<Text>();
str = text.text;
currentCount = 0;
totalCount = text.text.Length;
StartCoroutine(ShowText());
}
/// <summary>
/// 显示文本
/// </summary>
/// <returns></returns>
IEnumerator ShowText()
{
while (true)
{
currentCount++;
if (currentCount > totalCount)
{
yield break;
}
else
{
sb.Remove(0, sb.Length);
for (int i = 0; i < currentCount; i++)
{
sb.Append(str[i]);
}
text.text = sb.ToString();
yield return new WaitForSeconds(waitTime);
}
}
}
/// <summary>
/// 重置文本
/// </summary>
/// <param name="mText"></param>
public void ResetText(string mText)
{
StopAllCoroutines();
str = mText;
currentCount = 0;
totalCount = mText.Length;
StartCoroutine(ShowText());
}
void OnDestory()
{
sb = null;
}
}
阅读全文
0 0
- UGUI简易Typewriter
- Ugui 实现简易版的Joystick
- hdu 5470 Typewriter
- UGUI
- UGUI
- UGUI
- UGUI
- UGUI
- UGUI
- UGUI
- UGUI
- ugui
- UGUI
- UGUI
- UGUI
- UGUI
- uGUI
- Typewriter text that fits label beforehand
- java8 特性总结
- Managing Spark data handles in R
- centos6安装oracle 10gr2
- 数据库连接池
- Linux_Memcached 安装笔记
- UGUI简易Typewriter
- java小算法—数兔子问题
- C语言实现计算一年中过了多少天
- runtime 理解及实际应用
- Leetcode(3):Longest Substring Without Repeating Characters
- 南大周志华教授写给学生的话
- 在App中打开淘宝
- angular数据获取后,无法及时更新到页面
- [leetcode]: 367. Valid Perfect Square