DragonEggFlyIconCtrl.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using DG.Tweening;
  7. using FL.FGUI.Actions;
  8. using System;
  9. using UnityEngine;
  10. using XGame.Framework;
  11. using XGame.Framework.UI;
  12. namespace FL.FGUI
  13. {
  14. public struct 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 Tween _tween;
  29. private UIMoveBezierAction _actMove;
  30. protected override void OnEnable(object intent)
  31. {
  32. AddUIListenres();
  33. }
  34. protected override void OnDisable()
  35. {
  36. RemoveUIListenres();
  37. ClearMove();
  38. }
  39. #region UI事件
  40. private void AddUIListenres()
  41. {
  42. }
  43. private void RemoveUIListenres()
  44. {
  45. }
  46. #endregion
  47. public void ShowUI(FlyingIconParam flyingParam)
  48. {
  49. VM.ItemIcon.icon = flyingParam.iconName;
  50. PlayFlyingAni(flyingParam);
  51. VM.ScaleAni.Play();
  52. }
  53. private void PlayFlyingAni(FlyingIconParam flyingParam)
  54. {
  55. _actMove = ObjectPool.Acquire<UIMoveBezierAction>();
  56. _actMove.args.from = flyingParam.startPos;
  57. _actMove.args.to = flyingParam.endPos;
  58. _actMove.args.duration = 1000;
  59. _actMove.args.offset = 350;
  60. _actMove.args.delay = UnityEngine.Random.Range(0, 200);
  61. _actMove.args.ease = Ease.InOutSine;
  62. _actMove.args.onComplete = () =>
  63. {
  64. ClearMove();
  65. flyingParam.callback?.Invoke(flyingParam.bScore);
  66. };
  67. //XGame.Log.Debug($"飞行起始坐标:{flyingParam.startPos},终点坐标:{flyingParam.endPos}");
  68. _actMove.Start(VM);
  69. }
  70. private void ClearMove()
  71. {
  72. if (_actMove != null)
  73. {
  74. ObjectPool.Recycle(_actMove);
  75. _actMove = null;
  76. }
  77. }
  78. }
  79. }