2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.0 KiB

5 years ago
  1. using UnityEngine;
  2. namespace Unity.FPS.UI
  3. {
  4. public class NotificationToast : MonoBehaviour
  5. {
  6. [Tooltip("Text content that will display the notification text")]
  7. public TMPro.TextMeshProUGUI TextContent;
  8. [Tooltip("Canvas used to fade in and out the content")]
  9. public CanvasGroup CanvasGroup;
  10. [Tooltip("How long it will stay visible")]
  11. public float VisibleDuration;
  12. [Tooltip("Duration of the fade in")]
  13. public float FadeInDuration = 0.5f;
  14. [Tooltip("Duration of the fade out")]
  15. public float FadeOutDuration = 2f;
  16. public bool Initialized { get; private set; }
  17. float m_InitTime;
  18. public float TotalRunTime => VisibleDuration + FadeInDuration + FadeOutDuration;
  19. public void Initialize(string text)
  20. {
  21. TextContent.text = text;
  22. m_InitTime = Time.time;
  23. // start the fade out
  24. Initialized = true;
  25. }
  26. void Update()
  27. {
  28. if (Initialized)
  29. {
  30. float timeSinceInit = Time.time - m_InitTime;
  31. if (timeSinceInit < FadeInDuration)
  32. {
  33. // fade in
  34. CanvasGroup.alpha = timeSinceInit / FadeInDuration;
  35. }
  36. else if (timeSinceInit < FadeInDuration + VisibleDuration)
  37. {
  38. // stay visible
  39. CanvasGroup.alpha = 1f;
  40. }
  41. else if (timeSinceInit < FadeInDuration + VisibleDuration + FadeOutDuration)
  42. {
  43. // fade out
  44. CanvasGroup.alpha = 1 - (timeSinceInit - FadeInDuration - VisibleDuration) / FadeOutDuration;
  45. }
  46. else
  47. {
  48. CanvasGroup.alpha = 0f;
  49. // fade out over, destroy the object
  50. Destroy(gameObject);
  51. }
  52. }
  53. }
  54. }
  55. }