ScreenSnowController.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using UnityEngine;
  2. using System.Collections;
  3. public class ScreenSnowController : MonoBehaviour
  4. {
  5. public static ScreenSnowController Instance { get; private set; }
  6. [SerializeField] private TweenAlpha [] _tweens;
  7. private int _index;
  8. private bool forward = true;
  9. private float dur = 1.5f;
  10. // Use this for initialization
  11. private void Start()
  12. {
  13. if (!Instance)
  14. {
  15. Instance = this;
  16. return;
  17. }
  18. foreach (var tween in _tweens)
  19. {
  20. tween.onFinished.Add(new EventDelegate(OnTweenFinished));
  21. }
  22. foreach (var tween in _tweens)
  23. {
  24. tween.duration = dur;
  25. }
  26. }
  27. private void Update()
  28. {
  29. //if (Input.GetKeyDown(KeyCode.F3))
  30. //{
  31. // Duplicate();
  32. //}
  33. }
  34. private void OnTweenFinished()
  35. {
  36. //if (forward)
  37. //{
  38. // _index++;
  39. // if (_index == _tweens.Length)
  40. // {
  41. // forward = false;
  42. // foreach (var tween in _tweens)
  43. // {
  44. // tween.duration = dur;
  45. // }
  46. // foreach (var tween in _tweens)
  47. // {
  48. // tween.onFinished.Clear();
  49. // }
  50. // foreach (var tween in _tweens)
  51. // {
  52. // tween.onFinished.Add(new EventDelegate(OnTweenFinished));
  53. // }
  54. // _tweens[_tweens.Length - 1].Play(false);
  55. // }
  56. // else
  57. // {
  58. // _tweens[_index].Play(true);
  59. // }
  60. //}
  61. //else
  62. //{
  63. // _index--;
  64. // if (_index < 0)
  65. // {
  66. // Destroy(gameObject);
  67. // }
  68. // else
  69. // {
  70. // _tweens[_tweens.Length - 1].Play(false);
  71. // }
  72. //}
  73. }
  74. public void Duplicate()
  75. {
  76. var go = Instantiate(gameObject);
  77. go.transform.parent = transform.parent;
  78. go.transform.position = transform.position;
  79. go.transform.localScale = transform.localScale;
  80. go.SendMessage("Snow");
  81. }
  82. private void Snow()
  83. {
  84. StartCoroutine(Fade());
  85. }
  86. private IEnumerator Fade()
  87. {
  88. foreach (var tween in _tweens)
  89. {
  90. tween.duration = dur;
  91. tween.Play(true);
  92. }
  93. yield return new WaitForSeconds(1.5f);
  94. Destroy(gameObject);
  95. }
  96. }