ShowItemMoveToTargetPanel.cs 10 KB

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