//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, April 10, 2018
|
//--------------------------------------------------------
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class UGUITypewriter : MonoBehaviour
|
{
|
[SerializeField] Text m_text;
|
public float SPEED = 0.1f;
|
private float fSpeed = 0.1f;
|
string sContent=string.Empty;
|
//void Start()
|
//{
|
// SetContent();
|
//}
|
public void SetContent()
|
{
|
fSpeed = SPEED;
|
sContent = m_text.text;
|
curPos = 0;
|
fDelta = 0;
|
}
|
|
float fDelta;
|
int curPos = -1;
|
private void LateUpdate()
|
{
|
if (string.IsNullOrEmpty(sContent) && string.IsNullOrEmpty(m_text.text))
|
{
|
return;
|
}
|
if (!sContent.Contains(m_text.text))
|
{
|
SetContent();
|
return;
|
}
|
if (curPos == sContent.Length)
|
{
|
return;
|
}
|
fDelta += Time.deltaTime;
|
if (fDelta < fSpeed)
|
{
|
return;
|
}
|
fDelta -= fSpeed;
|
|
curPos++;
|
m_text.text = sContent.Substring(0, curPos);
|
|
}
|
public bool IsNext()
|
{
|
if (string.IsNullOrEmpty(sContent) && string.IsNullOrEmpty(m_text.text))
|
{
|
return true;
|
}
|
else if (curPos == sContent.Length)
|
{
|
return true;
|
}
|
else
|
{
|
fSpeed = 0;
|
return false;
|
}
|
}
|
}
|
|
}
|