using System.Collections.Generic; using CombatLibrary.CombatLibrary.CombatCore.Utility; using Common.Utility.CombatEvent; using Fort23.Core; using Fort23.UTool; using UnityEngine; using UnityEngine.UI; using Utility.UITool; namespace Fort23.Mono { [UIBinding(prefab = "ShowItemMoveToTargetPanel")] public partial class ShowItemMoveToTargetPanel : UIPanel { protected List allImageMove = new List(); public static async CTask OpenShowItemMoveToTargetPanel() { ShowItemMoveToTargetPanel showItemMoveToTargetPanel = await UIManager.Instance.LoadAndOpenPanel(null, UILayer.Middle, isFocus: false); } public static async void OpenShowItemMoveToTargetPanel(Vector2 startPos, Vector2 target, bool isStartPosUseWorld, bool isEndPosUseWorld, List allItem) { ShowItemMoveToTargetPanel showItemMoveToTargetPanel = await UIManager.Instance.LoadAndOpenPanel(null, UILayer.Top, isFocus: false); if (isStartPosUseWorld) { startPos = showItemMoveToTargetPanel.transform.worldToLocalMatrix * startPos; } if (isEndPosUseWorld) { target = showItemMoveToTargetPanel.transform.worldToLocalMatrix * target; } showItemMoveToTargetPanel.ShowPanel(startPos, target, allItem.Count, ""); } public static async void OpenShowItemMoveToTargetPanel(List allItem) { ShowItemMoveToTargetPanel showItemMoveToTargetPanel = await UIManager.Instance.LoadAndOpenPanel(null, UILayer.Top, isFocus: false); Vector2 target = showItemMoveToTargetPanel.moveTarget.GetComponent().anchoredPosition; showItemMoveToTargetPanel.moveTarget.gameObject.SetActive(true); showItemMoveToTargetPanel.ShowPanel(new Vector2(), target, allItem.Count, ""); } public static async void OpenShowItemMoveToTargetPanel(Vector2 startPos, Vector2 target, List allItem) { ShowItemMoveToTargetPanel showItemMoveToTargetPanel = await UIManager.Instance.LoadAndOpenPanel(null, UILayer.Top, isFocus: false); showItemMoveToTargetPanel.ShowPanel(startPos, target, allItem.Count, ""); } private void Init() { } protected override void AddEvent() { StaticUpdater.Instance.AddRenderUpdateCallBack(RenderUpdateCallBack); EventManager.Instance.AddEventListener(CustomEventType.Combat_ItemShow, Combat_ItemShow); } protected override void DelEvent() { StaticUpdater.Instance.RemoveRenderUpdateCallBack(RenderUpdateCallBack); EventManager.Instance.RemoveEventListener(CustomEventType.Combat_ItemShow, Combat_ItemShow); } public override void AddButtonEvent() { } protected void Combat_ItemShow(IEventData iEventData) { Vector2 target = moveTarget.GetComponent().anchoredPosition; CombatItemShowEventData combatItemShowEventData = iEventData as CombatItemShowEventData; if (combatItemShowEventData.isExp) { MainUIPanel mainUIPanel = UIManager.Instance.GetComponent(); Vector3 pos = mainUIPanel.expPoint.position; target = transform.worldToLocalMatrix * pos; } Vector3 p = UIManager.Instance.CurrCustomCameraStack.camera.WorldToScreenPoint( combatItemShowEventData.startPos_WorldPos); Vector3 p2 = UIManager.Instance.UICamera.ScreenToWorldPoint(p); Vector3 startPos = transform.worldToLocalMatrix * p2; ShowPanel(startPos, target, combatItemShowEventData.count, combatItemShowEventData.showName); } protected void RenderUpdateCallBack() { for (int i = 0; i < allImageMove.Count; i++) { ImageMove imageMove = allImageMove[i]; if (imageMove.Update()) { GObjectPool.Instance.Recycle(imageMove.GameObjectPool); allImageMove.RemoveAt(i); i--; } } if (allImageMove.Count <= 0) { moveTarget.gameObject.SetActive(false); } } public void AddACurve(Vector2 startPos, Vector2 target, string itemConfig) { ACurve aCurve = new ACurve(); CurveInfo curveInfo = new CurveInfo(); // Vector3 p = startPos + (startPos - target).normalized * 30; Vector3 moveTargetPos = startPos + new Vector2(Random.Range(-50, 50), Random.Range(-50, 50)); Vector2 newStartPos = moveTargetPos; curveInfo.t = newStartPos.x; curveInfo.v = newStartPos.y; curveInfo.BSLt = 0; // float x = Random.Range(-10, 10) * 30; Vector2 normal = (newStartPos - target).normalized; int x = Random.Range(0, 100) < 50 ? 1 : -1; normal = new Vector2(normal.y, -normal.x) * x * 300 + newStartPos; normal = (normal - target).normalized * 500; curveInfo.it = normal.x + curveInfo.t; curveInfo.ot = normal.y + curveInfo.v; CurveInfo curveInfo2 = new CurveInfo(); curveInfo2.t = target.x; curveInfo2.v = target.y; Vector3 normal2 = (newStartPos - target).normalized; curveInfo2.it = normal2.x + curveInfo2.t; curveInfo2.ot = normal2.y + curveInfo2.v + 10; curveInfo2.BSLt = 1; aCurve.CurveInfos = new List(); aCurve.CurveInfos.Add(curveInfo); aCurve.CurveInfos.Add(curveInfo2); aCurve.CurveType = CurveType.BSL; ImageMove currImageMove = new ImageMove(); currImageMove.SizeCurve = AnimationCurveManager.Instance.AnimationCurveLibrary.ui_moveSize; currImageMove.moveSpeed = AnimationCurveManager.Instance.AnimationCurveLibrary.ui_moveSpped; // currImageMove.ShowSizeCurve = AnimationCurveManager.Instance.AnimationCurveLibrary.ui_showSize; // currImageMove.showSizeSpeed = 10; GameObjectPool gameObjectPool = GObjectPool.Instance.FetchAsyncForGameObject(moveIcon.gameObject, "moveIcon"); gameObjectPool.own.transform.SetParent(transform); gameObjectPool.own.SetActive(false); gameObjectPool.own.transform.localScale = Vector3.zero; currImageMove.GameObjectPool = gameObjectPool; MyImage myImage= gameObjectPool.own.GetComponent(); myImage.onSpriteAlter= delegate { myImage.SetNativeSize(); }; myImage.icon_name = itemConfig; currImageMove.transform = gameObjectPool.own.GetComponent(); // currImageMove.transform.sizeDelta = new Vector2(35, 35); currImageMove.moveStartPos = startPos; currImageMove.moveTargetPos = moveTargetPos; currImageMove.transform.anchoredPosition = currImageMove.moveStartPos; currImageMove.yanChi = Random.Range(0, 0.5f); currImageMove.speed = AnimationCurveManager.Instance.AnimationCurveLibrary.uiMoveSpeed; currImageMove.currAcur = aCurve; allImageMove.Add(currImageMove); } public void ShowPanel(Vector2 startPos, Vector2 target, int count, string showName) { if (target.x == -5000) { target = moveTarget.GetComponent().anchoredPosition; } for (int i = 0; i < count; i++) { AddACurve(startPos, target, showName); } } } }