ShowItemMoveToTargetPanel.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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<ShowItemMoveToTargetPanel> OpenShowItemMoveToTargetPanel()
  20. {
  21. ShowItemMoveToTargetPanel showItemMoveToTargetPanel =
  22. await UIManager.Instance.LoadAndOpenPanel<ShowItemMoveToTargetPanel>(null, UILayer.Bottom,
  23. isFocus: false);
  24. return showItemMoveToTargetPanel;
  25. }
  26. private void Init()
  27. {
  28. }
  29. protected override void AddEvent()
  30. {
  31. StaticUpdater.Instance.AddRenderUpdateCallBack(RenderUpdateCallBack);
  32. }
  33. protected override void DelEvent()
  34. {
  35. StaticUpdater.Instance.RemoveRenderUpdateCallBack(RenderUpdateCallBack);
  36. }
  37. public override void AddButtonEvent()
  38. {
  39. }
  40. protected void RenderUpdateCallBack()
  41. {
  42. for (int i = 0; i < allImageMove.Count; i++)
  43. {
  44. ImageMove imageMove = allImageMove[i];
  45. if (imageMove.Update())
  46. {
  47. GObjectPool.Instance.Recycle(imageMove.GameObjectPool);
  48. allImageMove.RemoveAt(i);
  49. i--;
  50. }
  51. }
  52. if (allImageMove.Count <= 0)
  53. {
  54. moveTarget.gameObject.SetActive(false);
  55. }
  56. }
  57. private ImageMove AddACurve(Vector2 startPos, Vector2 target, string itemConfig, object data ,
  58. System.Action<ImageMove> finishCallBack, System.Action<ImageMove> targetPointSet)
  59. {
  60. ACurve aCurve = new ACurve();
  61. CurveInfo curveInfo = new CurveInfo();
  62. // Vector3 p = startPos + (startPos - target).normalized * 30;
  63. Vector3 moveTargetPos = startPos + new Vector2(Random.Range(-50, 50),
  64. Random.Range(-50, 50));
  65. Vector2 newStartPos = moveTargetPos;
  66. curveInfo.t = newStartPos.x;
  67. curveInfo.v = newStartPos.y;
  68. curveInfo.BSLt = 0;
  69. // float x = Random.Range(-10, 10) * 30;
  70. Vector2 normal = (newStartPos - target).normalized;
  71. int x = Random.Range(0, 100) < 50 ? 1 : -1;
  72. normal = new Vector2(normal.y, -normal.x) * x * 300 + newStartPos;
  73. normal = (normal - target).normalized * 500;
  74. curveInfo.it = normal.x + curveInfo.t;
  75. curveInfo.ot = normal.y + curveInfo.v;
  76. CurveInfo curveInfo2 = new CurveInfo();
  77. curveInfo2.t = target.x;
  78. curveInfo2.v = target.y;
  79. Vector3 normal2 = (newStartPos - target).normalized;
  80. curveInfo2.it = normal2.x + curveInfo2.t;
  81. curveInfo2.ot = normal2.y + curveInfo2.v + 10;
  82. curveInfo2.BSLt = 1;
  83. aCurve.CurveInfos = new List<CurveInfo>();
  84. aCurve.CurveInfos.Add(curveInfo);
  85. aCurve.CurveInfos.Add(curveInfo2);
  86. aCurve.CurveType = CurveType.BSL;
  87. ImageMove currImageMove = CObjectPool.Instance.Fetch<ImageMove>();
  88. currImageMove.finishCallBack = finishCallBack;
  89. currImageMove.targetPointSet = targetPointSet;
  90. currImageMove.data=data;
  91. currImageMove.SizeCurve = AnimationCurveManager.Instance.AnimationCurveLibrary.ui_moveSize;
  92. currImageMove.moveSpeed = AnimationCurveManager.Instance.AnimationCurveLibrary.ui_moveSpped;
  93. // currImageMove.ShowSizeCurve = AnimationCurveManager.Instance.AnimationCurveLibrary.ui_showSize;
  94. // currImageMove.showSizeSpeed = 10;
  95. GameObjectPool gameObjectPool =
  96. GObjectPool.Instance.FetchAsyncForGameObject<GameObjectPool>(moveIcon.gameObject, "moveIcon");
  97. gameObjectPool.own.transform.SetParent(transform);
  98. gameObjectPool.own.SetActive(false);
  99. gameObjectPool.own.transform.localScale = Vector3.zero;
  100. currImageMove.GameObjectPool = gameObjectPool;
  101. MyImage myImage = gameObjectPool.own.GetComponent<MyImage>();
  102. // myImage.onSpriteAlter = delegate { myImage.SetNativeSize(); };
  103. myImage.icon_name = itemConfig;
  104. currImageMove.transform = gameObjectPool.own.GetComponent<RectTransform>();
  105. currImageMove.transform.sizeDelta = new Vector2(50, 65);
  106. currImageMove.moveStartPos = startPos;
  107. currImageMove.transform.anchoredPosition = currImageMove.moveStartPos;
  108. currImageMove.yanChi = Random.Range(0, 0.5f);
  109. currImageMove.speed = AnimationCurveManager.Instance.AnimationCurveLibrary.uiMoveSpeed;
  110. currImageMove.currAcur = aCurve;
  111. allImageMove.Add(currImageMove);
  112. return currImageMove;
  113. }
  114. public void ShowPanel(Vector2 startPos, Vector2 target, int count, string showName,
  115. System.Action<ImageMove> finishCallBack = null, System.Action<ImageMove> targetPointSet = null,object data=null)
  116. {
  117. if (target.x == -5000)
  118. {
  119. target = moveTarget.GetComponent<RectTransform>().anchoredPosition;
  120. }
  121. for (int i = 0; i < count; i++)
  122. {
  123. ImageMove imageMove = AddACurve(startPos, target, showName, data, finishCallBack, targetPointSet);
  124. imageMove.GroupIndex = i;
  125. }
  126. }
  127. }
  128. }