using System;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using System.Collections;
|
/// <summary>
|
/// 播放文字脚本
|
/// </summary>
|
public class CharForeach : MonoBehaviour
|
{
|
public float letterPause = 1f;
|
private string word;
|
private Text text;
|
public delegate void CallBack();
|
private Action callBack;
|
|
//RectTransform contentRect;
|
|
//Vector2 offsetV;
|
void Awake()
|
{
|
//contentRect = transform.Find("Scroll View/Viewport/Content").GetComponent<RectTransform>();
|
//offsetV = new Vector2(0, 20);
|
text = transform.Find("Text").GetComponent<Text>();
|
}
|
|
public void StartShowWord(string str, Action cb)
|
{
|
//Debug.Log("StartShowWord" + str);
|
|
word = str;
|
text.text = "";
|
callBack = cb;
|
// if (contentRect.anchoredPosition.y != 0)
|
// {
|
// contentRect.anchoredPosition = Vector2.zero;
|
// }
|
StartCoroutine("TypeText");
|
}
|
|
public void ShowWordImmediately()
|
{
|
// Debug.Log("ShowWordImmediately");
|
StopCoroutine("TypeText");
|
text.text = "";
|
char[] charArray = word.ToCharArray();
|
//length = 0;
|
for (int i = 0; i < charArray.Length; i++)
|
{
|
if (charArray[i].Equals('$'))
|
{
|
text.text += GuideConfig.showWordsUBB[0];
|
//length += 19;
|
}
|
else if (charArray[i].Equals('%'))
|
{
|
//length += 19;
|
text.text += GuideConfig.showWordsUBB[1];
|
}
|
else if (charArray[i].Equals('`'))
|
{
|
//length += 23;
|
text.text += GuideConfig.showWordsUBB[2];
|
}
|
else if (charArray[i].Equals('&'))
|
{
|
//length += 19;
|
text.text += GuideConfig.showWordsUBB[3];
|
}
|
else if (charArray[i].Equals('*'))
|
{
|
//length += 23;
|
text.text += GuideConfig.showWordsUBB[4];
|
}
|
else if (charArray[i].Equals('<'))
|
{
|
//length += 23;
|
text.text += GuideConfig.showWordsUBB[5];
|
}
|
else
|
{
|
text.text += charArray[i];
|
}
|
|
}
|
//text.text = word;
|
|
// if (text.text.Length - length >= 39 && contentRect.anchoredPosition != offsetV)
|
// {
|
// contentRect.anchoredPosition = offsetV;
|
// }
|
// else
|
// {
|
// contentRect.anchoredPosition = Vector2.zero;
|
// }
|
if (callBack != null)
|
{
|
callBack();
|
callBack = null;
|
}
|
|
}
|
|
//int length = 0;
|
private IEnumerator TypeText()
|
{
|
char[] charArray = word.ToCharArray();
|
//length = 0;
|
for (int i = 0; i < charArray.Length; i++)
|
{
|
if (charArray[i].Equals('$'))
|
{
|
text.text += GuideConfig.showWordsUBB[0];
|
//length += 19;
|
}
|
else if (charArray[i].Equals('%'))
|
{
|
//length += 19;
|
text.text += GuideConfig.showWordsUBB[1];
|
}
|
else if (charArray[i].Equals('`'))
|
{
|
//length += 23;
|
text.text += GuideConfig.showWordsUBB[2];
|
}
|
else if (charArray[i].Equals('&'))
|
{
|
//length += 19;
|
text.text += GuideConfig.showWordsUBB[3];
|
}
|
else if (charArray[i].Equals('*'))
|
{
|
//length += 23;
|
text.text += GuideConfig.showWordsUBB[4];
|
}
|
else if (charArray[i].Equals('<'))
|
{
|
//length += 23;
|
text.text += GuideConfig.showWordsUBB[5];
|
}
|
else
|
{
|
text.text += charArray[i];
|
}
|
|
// if (text.text.Length - length >= 39 && contentRect.anchoredPosition != offsetV)
|
// {
|
// contentRect.anchoredPosition = offsetV;
|
// }
|
yield return new WaitForSeconds(letterPause);
|
}
|
|
|
if (callBack != null)
|
{
|
callBack();
|
callBack = null;
|
}
|
}
|
}
|