ShowItemMoveToTargetPanel.cs 10 KB

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