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.
 
 
 

62 lines
1.3 KiB

  1. using System;
  2. using CIG.Extensions;
  3. using SUISSEngine;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace CIG
  7. {
  8. public class BalloonView : GridTileIcon
  9. {
  10. protected virtual void OnDestroy()
  11. {
  12. if (this._balloon != null)
  13. {
  14. this._balloon.CollectedEvent -= this.OnCollected;
  15. this._balloon = null;
  16. }
  17. this.CancelInvoke(new Action(this.Expire));
  18. }
  19. public virtual void Init(Balloon balloon)
  20. {
  21. this._balloon = balloon;
  22. this._balloon.CollectedEvent += this.OnCollected;
  23. this.Invoke(new Action(this.Expire), this._balloon.TotalDurationInSeconds, false);
  24. }
  25. public virtual void OnBalloonClicked()
  26. {
  27. if (!this._hasCollected)
  28. {
  29. this._balloon.Collect();
  30. this._hasCollected = true;
  31. }
  32. }
  33. protected void ResetExpirationTimer()
  34. {
  35. this.CancelInvoke(new Action(this.Expire));
  36. this.Invoke(new Action(this.Expire), this._balloon.TotalDurationInSeconds, false);
  37. }
  38. private void Expire()
  39. {
  40. this._balloon.Expire();
  41. }
  42. private void OnCollected(Balloon balloon)
  43. {
  44. balloon.CollectedEvent -= this.OnCollected;
  45. this.CancelInvoke(new Action(this.Expire));
  46. }
  47. [SerializeField]
  48. private Button _button;
  49. protected Balloon _balloon;
  50. protected bool _hasCollected;
  51. }
  52. }