From 54181477c210344b037d88f17dbe2cddc5cbc930 Mon Sep 17 00:00:00 2001 From: chenxin <chenxin6991@163.com> Date: Wed, 02 Dec 2020 17:54:32 +0800 Subject: [PATCH] Merge branch 'master' of http://172.16.1.52:8090/r/GemBattle into master --- Assets/Scripts/Guide/CharForeach.cs | 193 ++++++++++++++++++++--------------------------- 1 files changed, 83 insertions(+), 110 deletions(-) diff --git a/Assets/Scripts/Guide/CharForeach.cs b/Assets/Scripts/Guide/CharForeach.cs index 11bfde4..26738dc 100644 --- a/Assets/Scripts/Guide/CharForeach.cs +++ b/Assets/Scripts/Guide/CharForeach.cs @@ -13,147 +13,120 @@ 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>(); + transform.Find("BGPanel").GetComponent<Button>().onClick.AddListener(OnClickBtn); } 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"); + } + + string[] wordArray; + int arrayIndex; + bool isStarting; + public void StartShowWord(string[] str, Action cb) + { + if (!isStarting) + { + wordArray = str; + arrayIndex = 0; + word = wordArray[arrayIndex]; + text.text = ""; + callBack = cb; + StartCoroutine("TypeText"); + } + } + + private void OnClickBtn() + { + if (isStarting) + { + ShowWordImmediately(); + } + else + { + if (wordArray != null && arrayIndex != wordArray.Length - 1) + { + arrayIndex++; + word = wordArray[arrayIndex]; + text.text = ""; + StartCoroutine("TypeText"); + } + else + { + if (callBack != null) + { + callBack(); + } + } + } } 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 (isStarting) { - if (charArray[i].Equals('$')) + StopCoroutine("TypeText"); + isStarting = false; + text.text = ""; + char[] charArray = word.ToCharArray(); + for (int i = 0; i < charArray.Length; i++) { - text.text += GuideConfig.showWordsUBB[0]; - //length += 19; + SetText(charArray[i]); } - 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() { + isStarting = true; 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; - // } + SetText(charArray[i]); yield return new WaitForSeconds(letterPause); } + isStarting = false; + yield break; + } - if (callBack != null) + private void SetText(char c) + { + if (c.Equals('$')) { - callBack(); - callBack = null; + text.text += GuideConfig.showWordsUBB[0]; + } + else if (c.Equals('%')) + { + text.text += GuideConfig.showWordsUBB[1]; + } + else if (c.Equals('`')) + { + text.text += GuideConfig.showWordsUBB[2]; + } + else if (c.Equals('&')) + { + text.text += GuideConfig.showWordsUBB[3]; + } + else if (c.Equals('*')) + { + text.text += GuideConfig.showWordsUBB[4]; + } + else if (c.Equals('<')) + { + text.text += GuideConfig.showWordsUBB[5]; + } + else + { + text.text += c; } } } -- Gitblit v1.9.1