FlashEffect.cs 850 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using UnityEngine;
  2. using DG.Tweening;
  3. public class FlashEffect : MonoBehaviour
  4. {
  5. private static FlashEffect instance;
  6. private static Tween showTween;
  7. public CanvasGroup fill;
  8. private void Awake()
  9. {
  10. instance = this;
  11. }
  12. private void OnDestroy()
  13. {
  14. instance = null;
  15. }
  16. private void Start()
  17. {
  18. fill.alpha = 0.0f;
  19. fill.gameObject.SetActive(false);
  20. }
  21. public static void Flash()
  22. {
  23. if (showTween != null) showTween.Kill();
  24. // was causing a problem with getting started game tutorial
  25. // mock for it
  26. if (!instance)
  27. return;
  28. instance.fill.gameObject.SetActive(true);
  29. instance.fill.alpha = 1.0f;
  30. showTween = instance.fill.DOFade(0.0f, 0.7f)
  31. .SetEase(Ease.OutQuart)
  32. .OnComplete(OnFlashComplete);
  33. }
  34. private static void OnFlashComplete()
  35. {
  36. showTween = null;
  37. instance.fill.gameObject.SetActive(false);
  38. }
  39. }