DragonEggFlyIconCtrl.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using DG.Tweening;
  7. using FL.Battle.Actions;
  8. using System;
  9. using UnityEngine;
  10. using XGame.Framework;
  11. using XGame.Framework.UI;
  12. namespace FL.FGUI
  13. {
  14. public class FlyingIconParam
  15. {
  16. public bool bScore;
  17. public Vector3 startPos;
  18. public Vector3 endPos;
  19. public string iconName;
  20. public Action<bool> callback;
  21. }
  22. /// <summary>
  23. /// UI逻辑处理类
  24. /// </summary>
  25. /// <typeparam name=""></typeparam>
  26. public partial class DragonEggFlyIconCtrl : UIController<DragonEggFlyIconVM>
  27. {
  28. private MoveBezierAction _actMove;
  29. protected override void OnEnable(object intent)
  30. {
  31. AddUIListenres();
  32. }
  33. protected override void OnDisable()
  34. {
  35. RemoveUIListenres();
  36. ClearMove();
  37. }
  38. #region UI事件
  39. private void AddUIListenres()
  40. {
  41. }
  42. private void RemoveUIListenres()
  43. {
  44. }
  45. #endregion
  46. public void ShowUI(FlyingIconParam flyingParam)
  47. {
  48. VM.ItemIcon.icon = flyingParam.iconName;
  49. PlayFlyingAni(flyingParam);
  50. VM.Scale.Play();
  51. }
  52. private void PlayFlyingAni(FlyingIconParam flyingParam)
  53. {
  54. _actMove = ObjectPool.Acquire<MoveBezierAction>();
  55. _actMove.args.from = flyingParam.startPos;
  56. _actMove.args.to = flyingParam.endPos;
  57. _actMove.args.duration = 1000;
  58. _actMove.args.delay = UnityEngine.Random.Range(0, 200);
  59. _actMove.args.ease = Ease.InOutSine;
  60. _actMove.args.onComplete = () =>
  61. {
  62. ClearMove();
  63. flyingParam?.callback?.Invoke(flyingParam.bScore);
  64. };
  65. _actMove.Start(VM.Tr, false);
  66. }
  67. private void ClearMove()
  68. {
  69. if (_actMove != null)
  70. {
  71. ObjectPool.Recycle(_actMove);
  72. _actMove = null;
  73. }
  74. }
  75. }
  76. }