From 439510ca0d2da7fa0af0496d4a05096841f01f8f Mon Sep 17 00:00:00 2001 From: wangguan <wangguan@kt007.com> Date: Mon, 26 Oct 2020 14:20:42 +0800 Subject: [PATCH] 新手引导2.0 --- Assets/Scripts/Guide/CharForeach.cs | 100 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 96 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Guide/CharForeach.cs b/Assets/Scripts/Guide/CharForeach.cs index 713db0c..69441ec 100644 --- a/Assets/Scripts/Guide/CharForeach.cs +++ b/Assets/Scripts/Guide/CharForeach.cs @@ -12,18 +12,28 @@ 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>(); text = transform.Find("Scroll View/Viewport/Content/Text").GetComponent<Text>(); + offsetV = new Vector2(0, 20); } public void StartShowWord(string str, Action cb) { - Debug.Log("StartShowWord"+str); + Debug.Log("StartShowWord" + str); word = str; text.text = ""; callBack = cb; + if (contentRect.anchoredPosition.y != 0) + { + contentRect.anchoredPosition = Vector2.zero; + } StartCoroutine("TypeText"); } @@ -31,7 +41,52 @@ { Debug.Log("ShowWordImmediately"); StopCoroutine("TypeText"); - text.text = word; + 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 + { + 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(); @@ -40,14 +95,51 @@ } + int length = 0; private IEnumerator TypeText() { - foreach (char letter in word.ToCharArray()) + char[] charArray = word.ToCharArray(); + length = 0; + for (int i = 0; i < charArray.Length; i++) { - text.text += letter; + 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 + { + 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(); -- Gitblit v1.9.1