ShowItemMoveToTargetPanel.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System.Collections.Generic;
  2. using CombatLibrary.CombatLibrary.CombatCore.Utility;
  3. using Common.Utility.CombatEvent;
  4. using Fort23.Core;
  5. using Fort23.UTool;
  6. using GameLogic.Bag;
  7. using GameLogic.Combat.CombatTool;
  8. using GameLogic.Combat.CombatType;
  9. using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
  10. using UnityEngine;
  11. using UnityEngine.UI;
  12. using Utility.UITool;
  13. namespace Fort23.Mono
  14. {
  15. [UIBinding(prefab = "ShowItemMoveToTargetPanel")]
  16. public partial class ShowItemMoveToTargetPanel : UIPanel
  17. {
  18. protected List<ImageMove> allImageMove = new List<ImageMove>();
  19. List<ImageMoveContainer> _imageMoveContainers = new List<ImageMoveContainer>();
  20. public static async CTask<ShowItemMoveToTargetPanel> OpenShowItemMoveToTargetPanel()
  21. {
  22. ShowItemMoveToTargetPanel showItemMoveToTargetPanel =
  23. await UIManager.Instance.LoadAndOpenPanel<ShowItemMoveToTargetPanel>(null, UILayer.Bottom,
  24. isFocus: false);
  25. return showItemMoveToTargetPanel;
  26. }
  27. public async override CTask Show()
  28. {
  29. await base.Show();
  30. Ui.sizeDelta = transform.sizeDelta;
  31. // Combat.sizeDelta = transform.sizeDelta;
  32. }
  33. private void Init()
  34. {
  35. }
  36. protected override void AddEvent()
  37. {
  38. StaticUpdater.Instance.AddRenderUpdateCallBack(RenderUpdateCallBack);
  39. }
  40. protected override void DelEvent()
  41. {
  42. StaticUpdater.Instance.RemoveRenderUpdateCallBack(RenderUpdateCallBack);
  43. }
  44. public override void AddButtonEvent()
  45. {
  46. }
  47. protected void RenderUpdateCallBack()
  48. {
  49. for (int i = 0; i < allImageMove.Count; i++)
  50. {
  51. ImageMove imageMove = allImageMove[i];
  52. if (imageMove.Update())
  53. {
  54. GObjectPool.Instance.Recycle(imageMove.GameObjectPool);
  55. allImageMove.RemoveAt(i);
  56. i--;
  57. }
  58. }
  59. if (allImageMove.Count <= 0)
  60. {
  61. moveTarget.gameObject.SetActive(false);
  62. }
  63. }
  64. private async CTask<ImageMove> AddACurve(Vector2 startPos, Vector2 target, string itemConfig, object data, CombatItemShowEventData.ShowType showType,
  65. System.Action<ImageMove> finishCallBack, System.Action<ImageMove> targetPointSet)
  66. {
  67. ACurve aCurve = new ACurve();
  68. CurveInfo curveInfo = new CurveInfo();
  69. // Vector3 p = startPos + (startPos - target).normalized * 30;
  70. Vector3 moveTargetPos = startPos + new Vector2(Random.Range(-50, 50),
  71. Random.Range(-50, 50));
  72. Vector2 newStartPos = moveTargetPos;
  73. curveInfo.t = newStartPos.x;
  74. curveInfo.v = newStartPos.y;
  75. curveInfo.BSLt = 0;
  76. // float x = Random.Range(-10, 10) * 30;
  77. Vector2 normal = (newStartPos - target).normalized;
  78. int x = Random.Range(0, 100) < 50 ? 1 : -1;
  79. normal = new Vector2(normal.y, -normal.x) * x * 300 + newStartPos;
  80. normal = (normal - target).normalized * 500;
  81. curveInfo.it = normal.x + curveInfo.t;
  82. curveInfo.ot = normal.y + curveInfo.v;
  83. CurveInfo curveInfo2 = new CurveInfo();
  84. curveInfo2.t = target.x;
  85. curveInfo2.v = target.y;
  86. Vector3 normal2 = (newStartPos - target).normalized;
  87. curveInfo2.it = normal2.x + curveInfo2.t;
  88. curveInfo2.ot = normal2.y + curveInfo2.v + 10;
  89. curveInfo2.BSLt = 1;
  90. aCurve.CurveInfos = new List<CurveInfo>();
  91. aCurve.CurveInfos.Add(curveInfo);
  92. aCurve.CurveInfos.Add(curveInfo2);
  93. aCurve.CurveType = CurveType.BSL;
  94. ImageMove currImageMove = CObjectPool.Instance.Fetch<ImageMove>();
  95. currImageMove.finishCallBack = finishCallBack;
  96. currImageMove.targetPointSet = targetPointSet;
  97. currImageMove.data = data;
  98. currImageMove.moveSpeed = AnimationCurveManager.Instance.AnimationCurveLibrary.ui_moveSpped;
  99. // currImageMove.ShowSizeCurve = AnimationCurveManager.Instance.AnimationCurveLibrary.ui_showSize;
  100. // currImageMove.showSizeSpeed = 10;
  101. GameObjectPool gameObjectPool;
  102. MyImage myImage;
  103. currImageMove.speed = AnimationCurveManager.Instance.AnimationCurveLibrary.uiMoveSpeed;
  104. gameObjectPool =
  105. GObjectPool.Instance.FetchAsyncForGameObject<GameObjectPool>(moveIcon.gameObject, "moveIcon");
  106. myImage = gameObjectPool.own.GetComponent<MyImage>();
  107. myImage.icon_name = itemConfig;
  108. // currImageMove.speed = AnimationCurveManager.Instance.AnimationCurveLibrary.uiMoveSpeed;
  109. // gameObjectPool =
  110. // GObjectPool.Instance.FetchAsyncForGameObject<GameObjectPool>(moveIcon.gameObject, "moveIcon");
  111. // myImage = gameObjectPool.own.GetComponent<MyImage>();
  112. // myImage.icon_name = itemConfig;
  113. currImageMove.SizeCurve = AnimationCurveManager.Instance.AnimationCurveLibrary.ui_moveSize;
  114. // gameObjectPool.own.transform.SetParent(Ui);
  115. gameObjectPool.own.SetActive(false);
  116. gameObjectPool.own.transform.localScale = Vector3.zero;
  117. currImageMove.GameObjectPool = gameObjectPool;
  118. currImageMove.transform = gameObjectPool.own.GetComponent<RectTransform>();
  119. currImageMove.transform.sizeDelta = new Vector2(50, 65);
  120. currImageMove.moveStartPos = startPos;
  121. currImageMove.transform.anchoredPosition = currImageMove.moveStartPos;
  122. currImageMove.yanChi = Random.Range(0, 0.5f);
  123. currImageMove.currAcur = aCurve;
  124. allImageMove.Add(currImageMove);
  125. return currImageMove;
  126. }
  127. public async void ShowPanel(Vector2 startPos, Vector2 target, int count, string showName, CombatItemShowEventData.ShowType showType,
  128. System.Action<ImageMove> finishCallBack = null, System.Action<ImageMove> targetPointSet = null, object data = null, System.Action<ImageMove> initCallBack = null)
  129. {
  130. if (target.x == -5000)
  131. {
  132. target = moveTarget.GetComponent<RectTransform>().anchoredPosition;
  133. }
  134. for (int i = 0; i < count; i++)
  135. {
  136. ImageMove imageMove = await AddACurve(startPos, target, showName, data, showType, finishCallBack, targetPointSet);
  137. imageMove.GroupIndex = i;
  138. initCallBack?.Invoke(imageMove);
  139. }
  140. }
  141. }
  142. }