UITutorialController.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections;
  3. using DG.Tweening;
  4. using DG.Tweening.Core;
  5. using DG.Tweening.Plugins.Options;
  6. using UnityEngine;
  7. public class UITutorialController : MonoBehaviour
  8. {
  9. public YieldInstruction PlayVideo(string path, string name)
  10. {
  11. return base.StartCoroutine(this.PlayVideoCoroutine(path, name));
  12. }
  13. public void DisposeVideo()
  14. {
  15. this._videoRenderer.gameObject.SetActive(false);
  16. this._playVideo.Dispose();
  17. }
  18. private IEnumerator PlayVideoCoroutine(string path, string name)
  19. {
  20. this._videoRenderer.gameObject.SetActive(true);
  21. this._playVideo = global::PlayVideo.CreateVideo(this._videoRenderer);
  22. yield return this._playVideo.Play(path, name, false);
  23. this.DisposeVideo();
  24. yield break;
  25. }
  26. public YieldInstruction Show(string str)
  27. {
  28. if (!this._generalTutorialWidgit.gameObject.activeInHierarchy)
  29. {
  30. this._generalTutorialWidgit.alpha = 0f;
  31. this._generalTutorialWidgit.gameObject.SetActive(true);
  32. this._generalLabel.text = str;
  33. return this.FadeIn(this._generalTutorialWidgit, 1f, false);
  34. }
  35. return this.FadeOut(this._generalTutorialWidgit, 1f, false);
  36. }
  37. public YieldInstruction Show(int id)
  38. {
  39. if (!this._tutorialWidgets[id].gameObject.activeInHierarchy)
  40. {
  41. this._tutorialWidgets[id].alpha = 0f;
  42. this._tutorialWidgets[id].gameObject.SetActive(true);
  43. return this.FadeIn(this._tutorialWidgets[id], 1f, false);
  44. }
  45. return this.FadeOut(this._tutorialWidgets[id], 1f, false);
  46. }
  47. public YieldInstruction Hide(int? id = null)
  48. {
  49. return base.StartCoroutine(this.HideCoroutine(id));
  50. }
  51. private IEnumerator HideCoroutine(int? id)
  52. {
  53. UIWidget widget = (id != null) ? this._tutorialWidgets[id.Value] : this._generalTutorialWidgit;
  54. if (widget.gameObject.activeInHierarchy && widget.alpha > 0f)
  55. {
  56. yield return this.FadeOut(widget, 1f, false);
  57. widget.gameObject.SetActive(false);
  58. }
  59. yield break;
  60. }
  61. private YieldInstruction FadeIn(UIWidget target, float during = 1f, bool ignoreTimeScale = false)
  62. {
  63. return this.FadeTo(target, 1f, during, ignoreTimeScale);
  64. }
  65. private YieldInstruction FadeOut(UIWidget target, float during = 1f, bool ignoreTimeScale = false)
  66. {
  67. return this.FadeTo(target, 0f, during, ignoreTimeScale);
  68. }
  69. private YieldInstruction FadeTo(UIWidget target, float endValue, float during, bool ignoreTimeScale)
  70. {
  71. return DOTween.To(() => target.alpha, delegate(float alpha)
  72. {
  73. target.alpha = alpha;
  74. }, endValue, during).SetUpdate(ignoreTimeScale).WaitForCompletion();
  75. }
  76. [SerializeField]
  77. private UIWidget _generalTutorialWidgit;
  78. [SerializeField]
  79. private UILabel _generalLabel;
  80. [SerializeField]
  81. private UIWidget[] _tutorialWidgets;
  82. [SerializeField]
  83. private Renderer _videoRenderer;
  84. private PlayVideo _playVideo;
  85. }