UILayerController.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using Core;
  3. using DG.Tweening;
  4. using ExtensionMethods;
  5. using UnityEngine;
  6. [RequireComponent(typeof(UIWidget))]
  7. public sealed class UILayerController : MonoBehaviour
  8. {
  9. private void Awake()
  10. {
  11. this._widget = base.GetComponent<UIWidget>();
  12. }
  13. private void Update()
  14. {
  15. if (this._lastLayer != null && Core.Input.UI.Cancel.OnClick)
  16. {
  17. this.OnCancelClick();
  18. }
  19. }
  20. public void OnCancelClick()
  21. {
  22. this._lastLayer.Appear();
  23. this.KillTweenerIfPlaying();
  24. this.Disappear();
  25. UIKeyInput.LoadHoveredObject();
  26. }
  27. public void Appear()
  28. {
  29. base.gameObject.SetActive(true);
  30. this.KillTweenerIfPlaying();
  31. this._widget.alpha = 0f;
  32. this._tweener = this._widget.DOFade(1f, 0.2f);
  33. }
  34. public void Disappear()
  35. {
  36. this.KillTweenerIfPlaying();
  37. this._widget.alpha = 0f;
  38. base.gameObject.SetActive(false);
  39. }
  40. private void KillTweenerIfPlaying()
  41. {
  42. if (this._tweener != null && this._tweener.IsPlaying())
  43. {
  44. this._tweener.Kill(false);
  45. }
  46. }
  47. [SerializeField]
  48. private UILayerController _lastLayer;
  49. private UIWidget _widget;
  50. private Tweener _tweener;
  51. }