From 7f9ec6d10ebb5d741b10e2b4168b11ad0ebb22cd Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期二, 11 十一月 2025 17:05:01 +0800
Subject: [PATCH] 125 战斗 飘血 护盾 满怒气 吸血反伤拆分

---
 Main/System/Battle/UIComp/DamageContent.cs |  135 ++++++++++++++++++++++++++++++++++++---------
 1 files changed, 108 insertions(+), 27 deletions(-)

diff --git a/Main/System/Battle/UIComp/DamageContent.cs b/Main/System/Battle/UIComp/DamageContent.cs
index 80be128..fddadfa 100644
--- a/Main/System/Battle/UIComp/DamageContent.cs
+++ b/Main/System/Battle/UIComp/DamageContent.cs
@@ -3,6 +3,7 @@
 using UnityEngine;
 using System;
 using Cysharp.Threading.Tasks;
+using DG.Tweening;
 
 public class DamageContent : MonoBehaviour, IBattleFloatingUI
 {
@@ -17,10 +18,16 @@
     private BattleDmgInfo battleDmgInfo;
     private BattleFloatingUIController controller;
 
+    #region Unity Lifecycle
+
     void Awake()
     {
         line.SetActive(false);
     }
+
+    #endregion
+
+    #region Controller Management
 
     private void InitController()
     {
@@ -42,6 +49,19 @@
         controller?.SetRatio(speed, scale);
     }
 
+    public void SetFloatingConfig(FloatingConfig config)
+    {
+        floatingConfig = config;
+        if (controller != null)
+        {
+            controller.SetConfig(config);
+        }
+    }
+
+    #endregion
+
+    #region Position Management
+
     /// <summary>
     /// 璁剧疆椋樺瓧鐨勮捣鐐瑰拰缁堢偣浣嶇疆锛堣繍琛屾椂鍔ㄦ�佽缃級
     /// </summary>
@@ -51,30 +71,95 @@
         controller?.SetRuntimePosition(beginPos, endPos);
     }
 
-    public async void SetDamage(BattleDmgInfo _battleDmgInfo, List<BattleDmg> damages, Action _onComplete)
+    #endregion
+
+    #region Damage Display
+
+    public void SetDamage(BattleDmgInfo _battleDmgInfo, List<BattleDmg> damages, Action _onComplete)
     {
         battleDmgInfo = _battleDmgInfo;
-        for (int i = damages.Count; i < damageLineList.Count; i++)
+        
+        EnsureDamageLineCapacity(damages.Count);
+        DisplayDamageLines(damages);
+        HideExcessDamageLines(damages.Count);
+        
+        bool isCrit = battleDmgInfo.IsCrit();
+        Play(isCrit, _onComplete);
+    }
+
+    /// <summary>
+    /// 纭繚鏈夎冻澶熺殑DamageLine瀵硅薄
+    /// </summary>
+    private void EnsureDamageLineCapacity(int requiredCount)
+    {
+        RectTransform lineTemplate = line.GetComponent<RectTransform>();
+        Vector2 templateAnchorMin = lineTemplate.anchorMin;
+        Vector2 templateAnchorMax = lineTemplate.anchorMax;
+        Vector2 templatePivot = lineTemplate.pivot;
+        
+        for (int i = damageLineList.Count; i < requiredCount; i++)
+        {
+            GameObject newLine = GameObject.Instantiate(line, parent);
+            DamageLine damageLine = newLine.GetComponent<DamageLine>();
+            
+            RectTransform newLineRect = newLine.GetComponent<RectTransform>();
+            if (newLineRect != null)
+            {
+                newLineRect.anchorMin = templateAnchorMin;
+                newLineRect.anchorMax = templateAnchorMax;
+                newLineRect.pivot = templatePivot;
+                newLineRect.anchoredPosition = Vector2.zero;
+                newLineRect.localScale = Vector3.one;
+            }
+            
+            damageLineList.Add(damageLine);
+        }
+    }
+
+    /// <summary>
+    /// 鏄剧ず浼ゅ琛屽苟璁剧疆浣嶇疆
+    /// </summary>
+    private void DisplayDamageLines(List<BattleDmg> damages)
+    {
+        for (int i = 0; i < damages.Count; i++)
+        {
+            DamageLine damageLine = damageLineList[i];
+            SetDamageLinePosition(damageLine, i);
+            damageLine.SetActive(true);
+            damageLine.SetDamage(damages[i]);
+        }
+    }
+
+    /// <summary>
+    /// 璁剧疆鍗曚釜浼ゅ琛岀殑浣嶇疆锛堜娇鐢╕杞村亸绉伙級
+    /// </summary>
+    private void SetDamageLinePosition(DamageLine damageLine, int index)
+    {
+        RectTransform lineRect = damageLine.GetComponent<RectTransform>();
+        if (lineRect == null) return;
+
+        RectTransform lineTemplate = line.GetComponent<RectTransform>();
+        Vector2 basePos = lineTemplate.anchoredPosition;
+        
+        Vector2 pos = basePos;
+        pos.y += 60f * index;
+        lineRect.anchoredPosition = pos;
+    }
+
+    /// <summary>
+    /// 闅愯棌澶氫綑鐨勪激瀹宠
+    /// </summary>
+    private void HideExcessDamageLines(int displayCount)
+    {
+        for (int i = displayCount; i < damageLineList.Count; i++)
         {
             damageLineList[i].SetActive(false);
         }
-
-        // 浣跨敤鎺у埗鍣ㄧ殑Play鏂规硶
-        bool isCrit = battleDmgInfo.IsCrit();
-        Play(isCrit, _onComplete);
-
-        for (int i = 0; i < damages.Count; i++)
-        {
-            if (i >= damageLineList.Count)
-            {
-                GameObject newLine = GameObject.Instantiate(line, parent);
-                damageLineList.Add(newLine.GetComponent<DamageLine>());
-            }
-            damageLineList[i].SetActive(true);
-            damageLineList[i].SetDamage(damages[i]);
-            await UniTask.Delay(100);
-        }
     }
+
+    #endregion
+
+    #region Animation Control
 
     public void Play(bool isCrit, Action onComplete = null)
     {
@@ -100,6 +185,10 @@
         controller.Resume();
     }
 
+    #endregion
+
+    #region Visual Effects
+
     private void ApplyColor(Color color)
     {
         for (int i = 0; i < damageLineList.Count; i++)
@@ -111,13 +200,5 @@
         }
     }
 
-    // 杩愯鏃舵洿鏂伴厤缃�
-    public void SetFloatingConfig(FloatingConfig config)
-    {
-        floatingConfig = config;
-        if (controller != null)
-        {
-            controller.SetConfig(config);
-        }
-    }
+    #endregion
 }

--
Gitblit v1.8.0