DetailInfoAnim.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections;
  3. using DG.Tweening;
  4. using UnityEngine;
  5. public class DetailInfoAnim : MonoBehaviour
  6. {
  7. private void Awake()
  8. {
  9. for (int i = 0; i < this.label.Length; i++)
  10. {
  11. this.label[i].text = string.Empty;
  12. }
  13. }
  14. public void StartAnim(params string[] info)
  15. {
  16. this._text = info;
  17. this.pointAnim.Play();
  18. this.widget.alpha = 0f;
  19. DOTween.To(delegate(float a)
  20. {
  21. this.widget.alpha = a;
  22. }, 0f, 1f, 1f);
  23. for (int i = 0; i < this.label.Length; i++)
  24. {
  25. base.StartCoroutine(this.ShowTextAnimCoroutine(i));
  26. }
  27. }
  28. public Coroutine FadeOut(float delayTime = 0f)
  29. {
  30. return base.StartCoroutine(this.FadeOutAnimCoroutine(delayTime));
  31. }
  32. private IEnumerator FadeOutAnimCoroutine(float delayTime)
  33. {
  34. yield return new WaitForSeconds(delayTime);
  35. for (int i = 0; i < this.label.Length; i++)
  36. {
  37. while (this.label[i].alpha > 0f)
  38. {
  39. this.label[i].transform.position += new Vector3(0f, 1f * Time.deltaTime);
  40. this.label[i].alpha -= 4f * Time.deltaTime;
  41. yield return new WaitForFixedUpdate();
  42. }
  43. }
  44. NGUITools.Destroy(base.gameObject);
  45. yield break;
  46. }
  47. private IEnumerator ShowTextAnimCoroutine(int index)
  48. {
  49. foreach (char str in this._text[index])
  50. {
  51. float duration = 0.5f;
  52. float delayTime = 0.02f;
  53. int times = Mathf.CeilToInt(duration / (float)this._text[index].Length / delayTime);
  54. for (int i = 1; i < times; i++)
  55. {
  56. UILabel uilabel = this.label[index];
  57. uilabel.text += this.randomString[UnityEngine.Random.Range(0, this.randomString.Length)];
  58. yield return new WaitForSeconds(delayTime);
  59. this.label[index].text = this.label[index].text.Remove(this.label[index].text.Length - 1);
  60. }
  61. UILabel uilabel2 = this.label[index];
  62. uilabel2.text += str;
  63. }
  64. yield break;
  65. }
  66. [SerializeField]
  67. private UILabel[] label;
  68. [SerializeField]
  69. private UIWidget widget;
  70. [SerializeField]
  71. private Animation pointAnim;
  72. private string[] _text = new string[3];
  73. private string randomString = "如果你也厌倦了这个浮华的市场如果你同样追求完美想尽情宣泄那天马行空的创造力加入我们体验不同寻常的游戏创造之路我们可以一起愉快地用显示器砸制作人";
  74. }