ShowItemMoveToTargetPanel.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. using Utility.UITool;
  10. namespace Fort23.Mono
  11. {
  12. [UIBinding(prefab = "ShowItemMoveToTargetPanel")]
  13. public partial class ShowItemMoveToTargetPanel : UIPanel
  14. {
  15. protected List<ImageMove> allImageMove = new List<ImageMove>();
  16. public static async CTask OpenShowItemMoveToTargetPanel()
  17. {
  18. ShowItemMoveToTargetPanel showItemMoveToTargetPanel =
  19. await UIManager.Instance.LoadAndOpenPanel<ShowItemMoveToTargetPanel>(null, UILayer.Middle,
  20. isFocus: false);
  21. }
  22. public static async void OpenShowItemMoveToTargetPanel(Vector2 startPos, Vector2 target,
  23. bool isStartPosUseWorld, bool isEndPosUseWorld,
  24. List<string> allItem)
  25. {
  26. ShowItemMoveToTargetPanel showItemMoveToTargetPanel =
  27. await UIManager.Instance.LoadAndOpenPanel<ShowItemMoveToTargetPanel>(null, UILayer.Top, isFocus: false);
  28. if (isStartPosUseWorld)
  29. {
  30. startPos = showItemMoveToTargetPanel.transform.worldToLocalMatrix * startPos;
  31. }
  32. if (isEndPosUseWorld)
  33. {
  34. target = showItemMoveToTargetPanel.transform.worldToLocalMatrix * target;
  35. }
  36. showItemMoveToTargetPanel.ShowPanel(startPos, target, allItem.Count, "");
  37. }
  38. public static async void OpenShowItemMoveToTargetPanel(List<string> allItem)
  39. {
  40. ShowItemMoveToTargetPanel showItemMoveToTargetPanel =
  41. await UIManager.Instance.LoadAndOpenPanel<ShowItemMoveToTargetPanel>(null, UILayer.Top, isFocus: false);
  42. Vector2 target = showItemMoveToTargetPanel.moveTarget.GetComponent<RectTransform>().anchoredPosition;
  43. showItemMoveToTargetPanel.moveTarget.gameObject.SetActive(true);
  44. showItemMoveToTargetPanel.ShowPanel(new Vector2(), target, allItem.Count, "");
  45. }
  46. public static async void OpenShowItemMoveToTargetPanel(Vector2 startPos, Vector2 target, List<string> allItem)
  47. {
  48. ShowItemMoveToTargetPanel showItemMoveToTargetPanel =
  49. await UIManager.Instance.LoadAndOpenPanel<ShowItemMoveToTargetPanel>(null, UILayer.Top, isFocus: false);
  50. showItemMoveToTargetPanel.ShowPanel(startPos, target, allItem.Count, "");
  51. }
  52. private void Init()
  53. {
  54. }
  55. protected override void AddEvent()
  56. {
  57. StaticUpdater.Instance.AddRenderUpdateCallBack(RenderUpdateCallBack);
  58. EventManager.Instance.AddEventListener(CustomEventType.Combat_ItemShow, Combat_ItemShow);
  59. }
  60. protected override void DelEvent()
  61. {
  62. StaticUpdater.Instance.RemoveRenderUpdateCallBack(RenderUpdateCallBack);
  63. EventManager.Instance.RemoveEventListener(CustomEventType.Combat_ItemShow, Combat_ItemShow);
  64. }
  65. public override void AddButtonEvent()
  66. {
  67. }
  68. protected void Combat_ItemShow(IEventData iEventData)
  69. {
  70. Vector2 target = moveTarget.GetComponent<RectTransform>().anchoredPosition;
  71. CombatItemShowEventData combatItemShowEventData = iEventData as CombatItemShowEventData;
  72. bool isExp = combatItemShowEventData.isExp;
  73. if (isExp)
  74. {
  75. MainUIPanel mainUIPanel = UIManager.Instance.GetComponent<MainUIPanel>();
  76. Vector3 pos = mainUIPanel.expPoint.position;
  77. target = transform.worldToLocalMatrix * pos;
  78. }
  79. Vector3 p = UIManager.Instance.CurrCustomCameraStack.camera.WorldToScreenPoint(
  80. combatItemShowEventData.startPos_WorldPos);
  81. Vector3 p2 = UIManager.Instance.UICamera.ScreenToWorldPoint(p);
  82. Vector3 startPos = transform.worldToLocalMatrix * p2;
  83. ShowPanel(startPos, target, combatItemShowEventData.count, combatItemShowEventData.showName, delegate
  84. {
  85. MainUIPanel mainUIPanel = UIManager.Instance.GetComponent<MainUIPanel>();
  86. if (mainUIPanel == null)
  87. {
  88. return;
  89. }
  90. if (isExp)
  91. {
  92. if (mainUIPanel != null)
  93. {
  94. ParticleSystemPool particleSystemPool =
  95. GObjectPool.Instance.FetchAsyncForGameObject<ParticleSystemPool>(mainUIPanel.fx_ui_exp,
  96. "fx_ui_exp");
  97. particleSystemPool.transform.SetParent(mainUIPanel.expPoint.transform);
  98. particleSystemPool.transform.localPosition = Vector3.zero;
  99. particleSystemPool.transform.localScale = Vector3.one;
  100. // particleSystemPool.transform.
  101. }
  102. }
  103. else
  104. {
  105. if (mainUIPanel != null)
  106. {
  107. ParticleSystemPool particleSystemPool =
  108. GObjectPool.Instance.FetchAsyncForGameObject<ParticleSystemPool>(mainUIPanel.fx_ui_coin,
  109. "fx_ui_coin");
  110. particleSystemPool.transform.SetParent(mainUIPanel.Icon_Coin.transform);
  111. particleSystemPool.transform.localPosition = Vector3.zero;
  112. particleSystemPool.transform.localScale = Vector3.one;
  113. // particleSystemPool.transform.
  114. }
  115. }
  116. });
  117. }
  118. protected void RenderUpdateCallBack()
  119. {
  120. for (int i = 0; i < allImageMove.Count; i++)
  121. {
  122. ImageMove imageMove = allImageMove[i];
  123. if (imageMove.Update())
  124. {
  125. GObjectPool.Instance.Recycle(imageMove.GameObjectPool);
  126. allImageMove.RemoveAt(i);
  127. i--;
  128. }
  129. }
  130. if (allImageMove.Count <= 0)
  131. {
  132. moveTarget.gameObject.SetActive(false);
  133. }
  134. }
  135. public void AddACurve(Vector2 startPos, Vector2 target, string itemConfig, System.Action finishCallBack)
  136. {
  137. ACurve aCurve = new ACurve();
  138. CurveInfo curveInfo = new CurveInfo();
  139. // Vector3 p = startPos + (startPos - target).normalized * 30;
  140. Vector3 moveTargetPos = startPos + new Vector2(Random.Range(-50, 50),
  141. Random.Range(-50, 50));
  142. Vector2 newStartPos = moveTargetPos;
  143. curveInfo.t = newStartPos.x;
  144. curveInfo.v = newStartPos.y;
  145. curveInfo.BSLt = 0;
  146. // float x = Random.Range(-10, 10) * 30;
  147. Vector2 normal = (newStartPos - target).normalized;
  148. int x = Random.Range(0, 100) < 50 ? 1 : -1;
  149. normal = new Vector2(normal.y, -normal.x) * x * 300 + newStartPos;
  150. normal = (normal - target).normalized * 500;
  151. curveInfo.it = normal.x + curveInfo.t;
  152. curveInfo.ot = normal.y + curveInfo.v;
  153. CurveInfo curveInfo2 = new CurveInfo();
  154. curveInfo2.t = target.x;
  155. curveInfo2.v = target.y;
  156. Vector3 normal2 = (newStartPos - target).normalized;
  157. curveInfo2.it = normal2.x + curveInfo2.t;
  158. curveInfo2.ot = normal2.y + curveInfo2.v + 10;
  159. curveInfo2.BSLt = 1;
  160. aCurve.CurveInfos = new List<CurveInfo>();
  161. aCurve.CurveInfos.Add(curveInfo);
  162. aCurve.CurveInfos.Add(curveInfo2);
  163. aCurve.CurveType = CurveType.BSL;
  164. ImageMove currImageMove = new ImageMove();
  165. currImageMove.finishCallBack = finishCallBack;
  166. currImageMove.SizeCurve = AnimationCurveManager.Instance.AnimationCurveLibrary.ui_moveSize;
  167. currImageMove.moveSpeed = AnimationCurveManager.Instance.AnimationCurveLibrary.ui_moveSpped;
  168. // currImageMove.ShowSizeCurve = AnimationCurveManager.Instance.AnimationCurveLibrary.ui_showSize;
  169. // currImageMove.showSizeSpeed = 10;
  170. GameObjectPool gameObjectPool =
  171. GObjectPool.Instance.FetchAsyncForGameObject<GameObjectPool>(moveIcon.gameObject, "moveIcon");
  172. gameObjectPool.own.transform.SetParent(transform);
  173. gameObjectPool.own.SetActive(false);
  174. gameObjectPool.own.transform.localScale = Vector3.zero;
  175. currImageMove.GameObjectPool = gameObjectPool;
  176. MyImage myImage = gameObjectPool.own.GetComponent<MyImage>();
  177. myImage.onSpriteAlter = delegate { myImage.SetNativeSize(); };
  178. myImage.icon_name = itemConfig;
  179. currImageMove.transform = gameObjectPool.own.GetComponent<RectTransform>();
  180. // currImageMove.transform.sizeDelta = new Vector2(35, 35);
  181. currImageMove.moveStartPos = startPos;
  182. currImageMove.moveTargetPos = moveTargetPos;
  183. currImageMove.transform.anchoredPosition = currImageMove.moveStartPos;
  184. currImageMove.yanChi = Random.Range(0, 0.5f);
  185. currImageMove.speed = AnimationCurveManager.Instance.AnimationCurveLibrary.uiMoveSpeed;
  186. currImageMove.currAcur = aCurve;
  187. allImageMove.Add(currImageMove);
  188. }
  189. public void ShowPanel(Vector2 startPos, Vector2 target, int count, string showName,
  190. System.Action finishCallBack = null)
  191. {
  192. if (target.x == -5000)
  193. {
  194. target = moveTarget.GetComponent<RectTransform>().anchoredPosition;
  195. }
  196. for (int i = 0; i < count; i++)
  197. {
  198. AddACurve(startPos, target, showName, finishCallBack);
  199. }
  200. }
  201. }
  202. }