unity使用协程实现打字效果
2018-01-12 19:18
811 查看
int m_tempIndex = -1;// 字幕数组的index
bool m_finishOne = false;// 完成一列字
bool m_isFontPlaying = true;// 正在播放字
string[] m_tempContent = null;// 临时存储表中的字幕
IEnumerator PlayText()
{// 打字
for (int i=0;i< m_tempContent[m_tempIndex].Length;++i)
{
if (m_tempIndex < m_contentArral.Length && m_tempIndex >= 0)
{
m_contentArral[m_tempIndex].text += m_tempContent[m_tempIndex][i];
yield return new WaitForSeconds(0.12f);
}
}
m_finishOne = true;
}
public void Update()
{
if (m_finishOne)
{// 完成一个
m_finishOne = false;
m_isFontPlaying = false;
}
if (!m_isFontPlaying)
{// 没有正在写字
if (m_tempIndex < m_contentArral.Length - 1)
{
m_isFontPlaying = true;
m_tempIndex++;
StartCoroutine(this.PlayText());
}
else
{
this.Destroy();
}
}
if (m_isPlayAnimation)
{// 开始播放动画
m_isPlayAnimation = false;
if (m_anim.clip != null)
{
m_isPlaying = true;
m_hideTime = TimeWrap.time + m_anim.clip.length;
}
}
if (m_isPlaying && TimeWrap.time > m_hideTime)
{// 正在播放动画,时间结束,
m_isPlaying = false;
//this.Destroy();
m_tempIndex = 0;
if (m_tempContent != null && m_tempIndex < m_tempContent.Length)
{// m_tempIndex符合数组长度,开启协程打字
StartCoroutine(this.PlayText());
}
}
}
bool m_finishOne = false;// 完成一列字
bool m_isFontPlaying = true;// 正在播放字
string[] m_tempContent = null;// 临时存储表中的字幕
IEnumerator PlayText()
{// 打字
for (int i=0;i< m_tempContent[m_tempIndex].Length;++i)
{
if (m_tempIndex < m_contentArral.Length && m_tempIndex >= 0)
{
m_contentArral[m_tempIndex].text += m_tempContent[m_tempIndex][i];
yield return new WaitForSeconds(0.12f);
}
}
m_finishOne = true;
}
public void Update()
{
if (m_finishOne)
{// 完成一个
m_finishOne = false;
m_isFontPlaying = false;
}
if (!m_isFontPlaying)
{// 没有正在写字
if (m_tempIndex < m_contentArral.Length - 1)
{
m_isFontPlaying = true;
m_tempIndex++;
StartCoroutine(this.PlayText());
}
else
{
this.Destroy();
}
}
if (m_isPlayAnimation)
{// 开始播放动画
m_isPlayAnimation = false;
if (m_anim.clip != null)
{
m_isPlaying = true;
m_hideTime = TimeWrap.time + m_anim.clip.length;
}
}
if (m_isPlaying && TimeWrap.time > m_hideTime)
{// 正在播放动画,时间结束,
m_isPlaying = false;
//this.Destroy();
m_tempIndex = 0;
if (m_tempContent != null && m_tempIndex < m_tempContent.Length)
{// m_tempIndex符合数组长度,开启协程打字
StartCoroutine(this.PlayText());
}
}
}
相关文章推荐
- Unity UGUI 使用 CCTween 实现 打字效果
- unity学习——使用协程实现延时效果
- Unity中使用Shader实现3D打印机效果
- 不使用jquery实现js打字效果示例分享
- Unity使用Cardboard、MojingSDK等VR插件的3DUI(UGUI)凝视效果的实现(V客学院知识分享)
- Idea使用插件实现ATOM的打字效果
- [Unity]背包效果-使用NGUI实现物品的拖拽效果Drag
- 使用 AJAX 实现 打字效果 、、 、
- unity中实现键盘打字的效果
- 使用Unity实现动态2D水效果
- unity使用AnimationCurve实现RPG中攻击与受伤时的分数的动态效果ScoreFlash
- unity使用vuforia实现模型AR效果
- unity 使用shader加rendertexture实现刮刮乐效果
- Unity中使用协程实现倒计时功能
- 使用多线程实现打字效果
- 使用ASP.NET AJAX实现(图片)幻灯片效果
- [翻译]使用ASP.NET AJAX实现幻灯片效果
- 第九课,使用混合来实现半透明效果
- 使用C#实现Form窗体的淡入淡出效果