UITrophyNotificationController.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using DG.Tweening;
  5. using ExtensionMethods;
  6. using UnityEngine;
  7. public class UITrophyNotificationController : MonoBehaviour
  8. {
  9. public void AwardTrophy(string trophyName, string spriteName)
  10. {
  11. this._trophyQueue.Enqueue(new UITrophyNotificationController.Trophy(trophyName, spriteName));
  12. if (!this._isPlaying)
  13. {
  14. this.AwardTrophy();
  15. }
  16. }
  17. private Coroutine AwardTrophy()
  18. {
  19. UITrophyNotificationController.Trophy trophy = this._trophyQueue.Dequeue();
  20. this._trophyName.text = trophy.TrophyName;
  21. this._trophyIcon.spriteName = trophy.SpriteName;
  22. this._widget.alpha = 1f;
  23. this._widget.transform.localPosition = new Vector3(0f, (float)this._widget.height, 0f);
  24. return base.StartCoroutine(this.AwardTrophyCoroutine());
  25. }
  26. private IEnumerator AwardTrophyCoroutine()
  27. {
  28. this._isPlaying = true;
  29. this._panel.gameObject.SetActive(true);
  30. yield return this._widget.transform.DOLocalMoveY(0f, 0.5f, false).WaitForCompletion();
  31. yield return new WaitForSeconds(5f);
  32. yield return this._widget.DOFade(0f, 0.5f).WaitForCompletion();
  33. this._panel.gameObject.SetActive(false);
  34. this._isPlaying = false;
  35. if (this._trophyQueue.Count != 0)
  36. {
  37. this.AwardTrophy();
  38. }
  39. yield break;
  40. }
  41. [SerializeField]
  42. private UIPanel _panel;
  43. [SerializeField]
  44. private UIWidget _widget;
  45. [SerializeField]
  46. private UILabel _trophyName;
  47. [SerializeField]
  48. private UISprite _trophyIcon;
  49. private bool _isPlaying;
  50. private readonly Queue<UITrophyNotificationController.Trophy> _trophyQueue = new Queue<UITrophyNotificationController.Trophy>();
  51. private class Trophy
  52. {
  53. public Trophy(string trophyName, string spriteName)
  54. {
  55. this.TrophyName = trophyName;
  56. this.SpriteName = spriteName;
  57. }
  58. public string TrophyName { get; set; }
  59. public string SpriteName { get; set; }
  60. }
  61. }