ShowItemNumberCom.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Drawing;
  2. using Fort23.Core;
  3. using GameLogic.Bag;
  4. using UnityEngine;
  5. using Utility.UITool;
  6. namespace Fort23.Mono
  7. {
  8. [UIBinding(prefab = "ShowItemNumberCom")]
  9. public partial class ShowItemNumberCom : UIComponent
  10. {
  11. private float _currentTime;
  12. private float _originY;
  13. private TimerEntity _timerEntity;
  14. private void Init()
  15. {
  16. }
  17. public override void AddEvent()
  18. {
  19. }
  20. public override void DelEvent()
  21. {
  22. }
  23. public override void AddButtonEvent()
  24. {
  25. }
  26. public static async CTask<ShowItemNumberCom> Open(Vector3 pos, ItemInfo itemInfo)
  27. {
  28. ShowItemNumberCom showItemNumberCom = await UIManager.Instance.CreateGComponent<ShowItemNumberCom>(null, UIManager.Instance.GetLayer(UILayer.Top));
  29. Vector3 p = UIManager.Instance.CurrCustomCameraStack.camera.WorldToScreenPoint(pos);
  30. Vector3 p2 = UIManager.Instance.UICamera.ScreenToWorldPoint(p);
  31. showItemNumberCom.GObjectPoolInterface.GetComponent<RectTransform>().position = p2;
  32. showItemNumberCom.ShowTips(itemInfo);
  33. return showItemNumberCom;
  34. }
  35. public void ShowTips(ItemInfo itemInfo)
  36. {
  37. Vector3 pos = transform.GetComponent<RectTransform>().localPosition;
  38. Text_Number.text = $"+{itemInfo.count}";
  39. Icon_Item.gameObject.SetActive(true);
  40. Text_Number.gameObject.SetActive(true);
  41. Icon_Item.icon_name = itemInfo.config.icon;
  42. _currentTime = 0;
  43. _originY = transform.GetComponent<RectTransform>().localPosition.y;
  44. _timerEntity = TimerComponent.Instance.AddTimer(20, (() => { Close(); }), 50, () =>
  45. {
  46. _currentTime += 0.02f;
  47. float offsetY = _originY + AnimationCurveManager.Instance.AnimationCurveLibrary.JumpY.Evaluate(_currentTime) * 100;
  48. transform.localPosition = new Vector3(pos.x, offsetY, pos.z);
  49. });
  50. }
  51. public override void Close()
  52. {
  53. UIManager.Instance.DormancyGComponent(this);
  54. _timerEntity?.Dispose();
  55. _timerEntity = null;
  56. base.Close();
  57. }
  58. }
  59. }