StoryM.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using DG.Tweening;
  4. using UnityEngine;
  5. using UnityEngine.Localization.Settings;
  6. using UnityEngine.UI;
  7. public class StoryM : MonoBehaviour {
  8. public TMPro.TextMeshProUGUI textStory;
  9. public RectTransform shapeBack;
  10. void Start() {
  11. StartCoroutine(test());
  12. }
  13. IEnumerator SetStoryText(string textCh, string textEn = "English", float hideTime = 2f) {
  14. textStory.text = LocalizationSettings.SelectedLocale.LocaleName == "Chinese (Simplified) (zh-CN)" ? textCh : textEn;
  15. LayoutRebuilder.ForceRebuildLayoutImmediate(textStory.rectTransform);
  16. DOTween.Kill("StoryBackground");
  17. shapeBack.DOScaleX((textStory.rectTransform.rect.width + 40f) / 100f, 0.06f).SetId("StoryBackground");
  18. yield return new WaitForSeconds(hideTime);
  19. }
  20. public void HideStoryText() {
  21. textStory.text = "";
  22. shapeBack.DOScaleX(0, 0.06f);
  23. }
  24. IEnumerator test() {
  25. while (true) {
  26. yield return StartCoroutine(SetStoryText("这是第一句话", "Eng" , 2f));
  27. yield return StartCoroutine(SetStoryText("这是第二句话,文本框大小改变了吗?"));
  28. HideStoryText();
  29. yield return new WaitForSeconds(2f);
  30. }
  31. }
  32. }