From 8581fb56f1bc0ad0c396a9f689be14e94e6ca00b Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期日, 28 九月 2025 19:57:19 +0800
Subject: [PATCH] 125 战斗 1.战斗层级无效问题 2.连击不回原位就直接开打的问题 3.特效延迟销毁问题 4.部分技能使用之后会卡死的问题

---
 Main/Component/UI/Common/RendererAdjuster.cs            |    6 +
 Main/System/Battle/BattleField/BattleRootNode.cs        |    8 ++
 Main/System/Battle/BattleUtility.cs                     |   40 ++-----------
 Main/System/Battle/Skill/SkillBase.cs                   |   40 ++++++++-----
 Main/System/Battle/Motion/MotionBase.cs                 |   36 +++++++-----
 Main/System/Battle/BattleEffectMgr.cs                   |   19 ++++++
 Main/System/Battle/BattleObject/BattleObjectLayerMgr.cs |    4 
 7 files changed, 84 insertions(+), 69 deletions(-)

diff --git a/Main/Component/UI/Common/RendererAdjuster.cs b/Main/Component/UI/Common/RendererAdjuster.cs
index 4ecc7ee..0825c59 100644
--- a/Main/Component/UI/Common/RendererAdjuster.cs
+++ b/Main/Component/UI/Common/RendererAdjuster.cs
@@ -17,6 +17,8 @@
 
     protected Canvas canvas;
 
+    public int canvasOffset = 1;
+
     public Action<string, int> onSortingChanged;
 
     protected void Awake()
@@ -39,7 +41,7 @@
         // skeletonAnimations.Clear();
         // skeletonAnimations.AddRange(gameObject.GetComponentsInChildren<SkeletonAnimation>(true));
 
-        canvas = GetComponentInChildren<Canvas>();
+        canvas = GetComponentInChildren<Canvas>(true);
     }
 
     public void UpdateSortingOrder()
@@ -65,7 +67,7 @@
 
         if (null != canvas)
         {
-            canvas.sortingOrder = sortingOrder + 1;
+            canvas.sortingOrder = sortingOrder + canvasOffset;
             if (!string.IsNullOrEmpty(sortingLayer))
             {
                 canvas.sortingLayerName = sortingLayer;
diff --git a/Main/System/Battle/BattleEffectMgr.cs b/Main/System/Battle/BattleEffectMgr.cs
index 4d8f83f..2c299de 100644
--- a/Main/System/Battle/BattleEffectMgr.cs
+++ b/Main/System/Battle/BattleEffectMgr.cs
@@ -15,6 +15,25 @@
         battleField = _battleField;
     }
 
+    public void Run()
+    {
+        List<BattleEffectPlayer> runList = new List<BattleEffectPlayer>();
+
+        foreach (KeyValuePair<int, List<BattleEffectPlayer>> kvPair in effectDict)
+        {
+            runList.AddRange(kvPair.Value);
+        }
+
+        for (int i = runList.Count - 1; i >= 0; i--)
+        {
+            BattleEffectPlayer effectPlayer = runList[i];
+            if (effectPlayer != null)
+            {
+                effectPlayer.Run();
+            }
+        }
+    }
+
     public void PauseGame()
     {
         foreach (KeyValuePair<int, List<BattleEffectPlayer>> kvPair in effectDict)
diff --git a/Main/System/Battle/BattleField/BattleRootNode.cs b/Main/System/Battle/BattleField/BattleRootNode.cs
index a665283..03c4e69 100644
--- a/Main/System/Battle/BattleField/BattleRootNode.cs
+++ b/Main/System/Battle/BattleField/BattleRootNode.cs
@@ -33,6 +33,8 @@
 	public RectTransform battleNodePos1;
 	public RectTransform battleNodePos2;
 
+	public RendererAdjuster rendererAdjuster;
+
 	void Awake()
 	{
 		for (int i = 1; i <= TeamConst.MaxTeamSlotCount; i++)
@@ -44,6 +46,7 @@
 			_blueTeamNodeList.Add(blueTrans.gameObject);
 		}
 		DontDestroyOnLoad(gameObject);
+		// SetSortingOrder();
 	}
 
 	public void SetBackground(Texture texture)
@@ -55,6 +58,11 @@
 		}
 	}
 
+	public void SetSortingOrder()
+	{
+		rendererAdjuster.SetSortingOrder(BattleConst.BlockerSortingOrder);
+	}
+
 	public Transform skillBackNode;
 
 	public Transform skillFrontNode;
diff --git a/Main/System/Battle/BattleObject/BattleObjectLayerMgr.cs b/Main/System/Battle/BattleObject/BattleObjectLayerMgr.cs
index 036b165..7e0eed3 100644
--- a/Main/System/Battle/BattleObject/BattleObjectLayerMgr.cs
+++ b/Main/System/Battle/BattleObject/BattleObjectLayerMgr.cs
@@ -65,8 +65,8 @@
         {
             effectPlayers[i].SetActive(isFront);
         }
-
-        int order = isFront ? BattleConst.ActiveHeroSortingOrder : BattleConst.UnactiveHeroSortingOrder;
+        //  绛栧垝瑕佸湪閲婃斁鎶�鑳界殑鏃跺�� 鍏朵粬瑙掕壊闅愯棌 杩欓噷鍦╞ack鐨勬椂鍊欏氨鐩存帴璁剧疆鎴�0  鍦ㄦ渶搴曚笅 鐪嬩笉鍒扮殑鍦版柟
+        int order = isFront ? BattleConst.ActiveHeroSortingOrder : 0; //BattleConst.UnactiveHeroSortingOrder;
         SetSortingOrder(order);
     }
 
diff --git a/Main/System/Battle/BattleUtility.cs b/Main/System/Battle/BattleUtility.cs
index 3d39c4e..03d2cda 100644
--- a/Main/System/Battle/BattleUtility.cs
+++ b/Main/System/Battle/BattleUtility.cs
@@ -63,9 +63,12 @@
     public static TweenerCore<Vector2, Vector2, DG.Tweening.Plugins.Options.VectorOptions> MoveToTarget(
         RectTransform transform, RectTransform target, Vector2 offset, Action onComplete = null, float speed = 500f)
     {
+        // 鑾峰彇鐩爣鑺傜偣鐨勪笘鐣屽潗鏍囷紙閿氱偣浣嶇疆锛�
+        Vector3 worldPos = target.position;
 
-        // 鑾峰彇鐩爣鑺傜偣鐨勪笘鐣屽潗鏍囷紙涓績鐐癸級
-        Vector3 worldPos = target.TransformPoint(target.rect.center + offset);
+        // 濡傛灉闇�瑕佸姞 offset锛岄渶鑰冭檻 scale
+        Vector3 offsetWorld = target.TransformVector(offset);
+        worldPos += offsetWorld;
 
         RectTransform canvasRect = transform.parent as RectTransform;
 
@@ -77,45 +80,14 @@
             null,
             out localPoint);
 
-        // 鍒涘缓RawImage
         float distance = Vector2.Distance(transform.anchoredPosition, localPoint);
-
-        float duration = distance / speed; // 鍋囪閫熷害涓�1000鍗曚綅/绉掞紝鍙互鏍规嵁闇�瑕佽皟鏁�
+        float duration = distance / speed;
 
         var tween = transform.DOAnchorPos(localPoint, duration).SetEase(Ease.Linear);
         tween.onComplete += () =>
         {
             onComplete?.Invoke();
         };
-
-        // MarkStartAndEnd(transform as RectTransform, target);
-
-
-        // // 1. 鑾峰彇鐩爣鐨勪笘鐣屽潗鏍囷紙鍔� offset锛�
-        // Vector3 targetWorldPos = target.TransformPoint(target.anchoredPosition + offset);
-
-        // // 2. 鑾峰彇婧愯妭鐐圭殑 parent
-        // RectTransform sourceParent = transform.parent as RectTransform;
-        // if (sourceParent == null)
-        // {
-        //     BattleDebug.LogError("婧愯妭鐐规病鏈夌埗鑺傜偣锛屾棤娉曡浆鎹㈠潗鏍囷紒");
-        //     return null;
-        // }
-
-        // // 3. 鎶婄洰鏍囦笘鐣屽潗鏍囪浆鎹㈠埌婧� parent 鐨勬湰鍦板潗鏍�
-        // Vector2 targetAnchoredPos;
-        // RectTransformUtility.ScreenPointToLocalPointInRectangle(
-        //     sourceParent,
-        //     RectTransformUtility.WorldToScreenPoint(CameraManager.uiCamera, targetWorldPos),
-        //     CameraManager.uiCamera,
-        //     out targetAnchoredPos);
-
-        // // 4. DOTween 绉诲姩
-        // var tween = transform.DOAnchorPos(targetAnchoredPos, duration).SetEase(Ease.Linear);
-        // tween.onComplete += () =>
-        // {
-        //     onComplete?.Invoke();
-        // };
 
         return tween;
     }
diff --git a/Main/System/Battle/Motion/MotionBase.cs b/Main/System/Battle/Motion/MotionBase.cs
index 5e652f0..6a5d57f 100644
--- a/Main/System/Battle/Motion/MotionBase.cs
+++ b/Main/System/Battle/Motion/MotionBase.cs
@@ -111,6 +111,11 @@
     /// <returns>鍔ㄧ敾杞ㄩ亾鏉$洰</returns>
     public virtual Spine.TrackEntry PlayAnimation(MotionName motionName, bool loop, Action _onComplete = null)
     {
+        if (isPlaySkillAnimation)
+        {
+            return null;
+        }
+
         if (spineAnimationState == null) return null;
 
         // 濡傛灉褰撳墠鍔ㄧ敾鏈畬鎴�
@@ -147,17 +152,19 @@
         runActionList.Remove(_action);
     }
 
+    private bool isPlaySkillAnimation = false;
+
     public Spine.TrackEntry PlaySkillAnimation(SkillConfig skillConfig, SkillBase skillBase, Action _onComplete = null)
     {
         // 鍙傛暟鏍¢獙
         if (skillConfig == null)
         {
-            BattleDebug.LogError("鎶�鑳介厤缃负绌猴紝鏃犳硶鎾斁鎶�鑳藉姩鐢�");
+            Debug.LogError("鎶�鑳介厤缃负绌猴紝鏃犳硶鎾斁鎶�鑳藉姩鐢�");
             return null;
         }
         if (spineAnimationState == null || skeleton == null)
         {
-            BattleDebug.LogError("SkeletonGraphic鎴朅nimationState鏈垵濮嬪寲锛屾棤娉曟挱鏀炬妧鑳藉姩鐢�");
+            Debug.LogError("SkeletonGraphic鎴朅nimationState鏈垵濮嬪寲锛屾棤娉曟挱鏀炬妧鑳藉姩鐢�");
             return null;
         }
 
@@ -181,7 +188,7 @@
         // 鑾峰彇鍔ㄧ敾
         if (anim == null)
         {
-            BattleDebug.LogError($"鎵句笉鍒板姩鐢�: {skillConfig.SkillMotionName}");
+            Debug.LogError($"鎵句笉鍒板姩鐢�: {skillConfig.SkillMotionName}");
             _onComplete?.Invoke();
             return null;
         }
@@ -194,11 +201,11 @@
 
         // 鎾斁鍔ㄧ敾
         var skillTrackEntry = spineAnimationState.SetAnimation(0, anim, false);
+        isPlaySkillAnimation = true;
         currentTrackEntry = skillTrackEntry;
 
         // 浜嬩欢鐘舵��
         int curLoop = 0;
-        bool isFinish = false;
         bool beginPhaseTriggered = false;
         bool finalFrameStarted = false;
         bool finalFrameEnded = false;
@@ -216,21 +223,24 @@
 
         updateLocalHandler = () =>
         {
-            if (isFinish) return;
-
             float frame = (skillTrackEntry.TrackTime * skillTrackEntry.TimeScale * (float)BattleConst.skillMotionFps);
+
+            if (currentTrackEntry != skillTrackEntry)
+            {
+                Debug.LogError("鎶�鑳藉姩鐢昏鎵撴柇锛屽己鍒剁粨鏉� " + skillConfig.SkillID + " last animation : " + (currentTrackEntry != null && currentTrackEntry.Animation != null ? currentTrackEntry.Animation.Name : "null"));
+            }
 
             if (skillTrackEntry.TrackTime == 0)
             {
                 failCallbackTimes++;
             }
-            
+
             if (failCallbackTimes > 100)
             {
                 Debug.LogError("鎶�鑳藉姩鐢绘挱鏀惧け璐ワ紝鍥炶皟寮傚父锛屽己鍒剁粨鏉� " + skillConfig.SkillID + " 瀵艰嚧閿欒鐨勫師鍥犳槸鎶�鑳藉抚閰嶇疆寰楀お涔呭鑷存妧鑳藉姩浣滅粨鏉熶簡浜嬩欢杩樻病缁撴潫");
                 skillBase.ForceFinished();
                 RemoveRunAction(updateLocalHandler);
-                isFinish = true;
+                isPlaySkillAnimation = true;
                 return;
             }
 
@@ -302,17 +312,13 @@
                 if (finalFrameStarted && !finalFrameEnded && frame >= recoveryFrame)
                 {
                     finalFrameEnded = true;
-                    skillBase.OnFinalFrameEnd();
+                    isPlaySkillAnimation = false;
                     RemoveRunAction(updateLocalHandler);
-                    isFinish = true;
+                    _onComplete?.Invoke();
+                    skillBase.OnFinalFrameEnd();
                 }
             }
         };
-
-        if (_onComplete != null && currentTrackEntry != null)
-        {
-            trackEntryCompleteDict[currentTrackEntry] = _onComplete;
-        }
 
         RunAction(updateLocalHandler);
 
diff --git a/Main/System/Battle/Skill/SkillBase.cs b/Main/System/Battle/Skill/SkillBase.cs
index 232a5ea..ed22592 100644
--- a/Main/System/Battle/Skill/SkillBase.cs
+++ b/Main/System/Battle/Skill/SkillBase.cs
@@ -50,7 +50,7 @@
 		battleField = _battleField;
 		packList = _packList;
 
-
+		// Debug.LogError("start a skill id " + skillConfig.SkillID + " caster " + caster.teamHero.heroId + " pos " + caster.teamHero.positionNum + " camp " + caster.Camp);
 
 	}
 
@@ -79,7 +79,10 @@
 			}
 			else
 			{
-				otherSkillAction.Run();
+				if (moveFinished)
+				{
+					otherSkillAction.Run();
+				}
 			}
 			return;
 		}
@@ -89,6 +92,7 @@
 	// 1路绉诲姩鍒拌窛绂婚樀瀹逛綅缃畁鐮佺殑璺濈锛堝2鍙蜂綅锛�5鍙蜂綅锛夐噴鏀撅紙鍗虫垬鍦轰腑澶绫伙級
 	public virtual void Cast()
 	{
+		// Debug.LogError("Cast skill " + skillConfig.SkillID + " cast position " + skillConfig.CastPosition + " cast mode " + skillConfig.castMode); 
 		string guid = battleField.guid;
 		TeamHero teamHero = caster.teamHero;
 		EventBroadcast.Instance.Broadcast<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, guid, skillConfig, teamHero);
@@ -162,6 +166,8 @@
 			_onComplete?.Invoke();
 		}, speed);
 		battleField.battleTweenMgr.OnPlayTween(tweener);
+
+		// Debug.LogError("move to tarrget " + target.name + " offset " + offset + " speed " + speed + " time " + tweener.Duration());
 	}
 
 	protected void TurnBack(Action _onComplete, float forward)
@@ -244,6 +250,16 @@
 	protected virtual void OnAllAttackMoveFinished()
 	{
 		moveFinished = true;
+		List<BattleObject> allList = battleField.battleObjMgr.allBattleObjDict.Values.ToList<BattleObject>();
+		for (int i = 0; i < allList.Count; i++)
+		{
+			BattleObject bo = allList[i];
+			bo.layerMgr.SetFront();
+			// bo.heroRectTrans.SetParent(battleField.GetTeamNode(bo.Camp, bo.teamHero.positionNum), true);
+			bo.heroInfoBar.SetActive(true);
+		}
+		battleField.battleRootNode.skillMaskNode.SetActive(false);
+		// Debug.LogError("OnAllAttackMoveFinished skill " + skillConfig.SkillID + " cast position " + skillConfig.CastPosition + " cast mode " + skillConfig.castMode); 
 	}
 
 	protected void CastToAllies()
@@ -365,6 +381,8 @@
 
 		caster.heroInfoBar.SetActive(false);
 
+		
+
 		for (int i = 0; i < allList.Count; i++)
 		{
 			BattleObject bo = allList[i];
@@ -372,12 +390,12 @@
 			{
 				bo.layerMgr.SetFront();
 				bo.heroInfoBar.SetActive(true);
-				bo.heroRectTrans.SetParent(battleField.battleRootNode.skillFrontNode, true);
+				// bo.heroRectTrans.SetParent(battleField.battleRootNode.skillFrontNode, true);
 			}
 			else
 			{
 				bo.layerMgr.SetBack();
-				bo.heroRectTrans.SetParent(battleField.battleRootNode.skillBackNode, true);
+				// bo.heroRectTrans.SetParent(battleField.battleRootNode.skillBackNode, true);
 			}
 
 			if (targetList.Contains(bo))
@@ -393,7 +411,7 @@
 		caster.layerMgr.SetSortingOrder(BattleConst.ActiveHeroActionSortingOrder);
 
 		battleField.battleRootNode.skillMaskNode.SetActive(true);
-
+		battleField.battleRootNode.SetSortingOrder();
 		// caster.battleField.skillMask
 		//	鎶婅繖浜汢O鍏ㄩ珮浜� 鎴栬�呰鎶婇櫎浜嗚繖浜涚殑閮芥斁鍦ㄩ伄缃╁悗闈�
 		//	YYL TODO
@@ -646,23 +664,13 @@
 
 		if (isFinished && moveFinished)
 		{
-			List<BattleObject> allList = battleField.battleObjMgr.allBattleObjDict.Values.ToList<BattleObject>();
-			for (int i = 0; i < allList.Count; i++)
-			{
-				BattleObject bo = allList[i];
-				bo.layerMgr.SetFront();
-				bo.heroRectTrans.SetParent(battleField.GetTeamNode(bo.Camp, bo.teamHero.positionNum), true);
-				bo.heroInfoBar.SetActive(true);
-			}
-			battleField.battleRootNode.skillMaskNode.SetActive(false);
-
 			if (packList.Count > 0)
 			{
 				OnSkillFinished();
 				return false;
 			}
 
-			return packList.Count <= 0;
+			return true;
 		}
 		else
 		{

--
Gitblit v1.8.0