ScreenSnowController.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. // Use this for initialization
  10. private void Start()
  11. {
  12. if (!Instance)
  13. {
  14. Instance = this;
  15. return;
  16. }
  17. //foreach (var tween in _tweens)
  18. //{
  19. // tween.onFinished.Add(new EventDelegate(OnTweenFinished));
  20. //}
  21. //foreach (var tween in _tweens)
  22. //{
  23. // tween.duration = 0.3f;
  24. //}
  25. }
  26. private void Update()
  27. {
  28. if (Input.GetKeyDown(KeyCode.F3))
  29. {
  30. Duplicate();
  31. }
  32. }
  33. //private void OnTweenFinished()
  34. //{
  35. // if (forward)
  36. // {
  37. // _index++;
  38. // if (_index == _tweens.Length)
  39. // {
  40. // forward = false;
  41. // foreach (var tween in _tweens)
  42. // {
  43. // tween.duration = 1f;
  44. // }
  45. // foreach (var tween in _tweens)
  46. // {
  47. // tween.onFinished.Clear();
  48. // }
  49. // foreach (var tween in _tweens)
  50. // {
  51. // tween.onFinished.Add(new EventDelegate(OnTweenFinished));
  52. // }
  53. // _tweens[_tweens.Length - 1].Play(false);
  54. // }
  55. // else
  56. // {
  57. // _tweens[_index].Play(true);
  58. // }
  59. // }
  60. // else
  61. // {
  62. // _index--;
  63. // if (_index < 0)
  64. // {
  65. // Destroy(gameObject);
  66. // }
  67. // else
  68. // {
  69. // _tweens[_tweens.Length - 1].Play(false);
  70. // }
  71. // }
  72. //}
  73. public void Duplicate()
  74. {
  75. var go = Instantiate(gameObject);
  76. go.transform.parent = transform.parent;
  77. go.transform.position = transform.position;
  78. go.transform.localScale = transform.localScale;
  79. go.SendMessage("Snow");
  80. }
  81. private void Snow()
  82. {
  83. StartCoroutine(Fade());
  84. }
  85. private IEnumerator Fade()
  86. {
  87. foreach (var tween in _tweens)
  88. {
  89. tween.duration = 0.3f;
  90. tween.Play(true);
  91. }
  92. yield return new WaitForSeconds(0.4f);
  93. for (int i = _tweens.Length - 1; i >= 0; i--)
  94. {
  95. _tweens[i].duration = 0.5f;
  96. _tweens[i].Play(false);
  97. yield return new WaitForSeconds(0.3f);
  98. }
  99. Destroy(gameObject);
  100. }
  101. }