| using UnityEngine; | 
| using System.Collections; | 
| using System.Collections.Generic; | 
| using UnityEngine.UI; | 
| using DG.Tweening; | 
| using Cysharp.Threading.Tasks; | 
|   | 
|   | 
| //  这个界面是 persistent的界面 | 
| public class BattleHUDWin : UIBase | 
| { | 
|     // 组件引用 | 
|     // private List<HUDContent> damageList = new List<HUDContent>(); | 
|   | 
|     // private List<BuffContent> buffList = new List<BuffContent>(); | 
|   | 
|     private GameObjectPoolManager.GameObjectPool damagePrefabPool; | 
|   | 
|     private GameObjectPoolManager.GameObjectPool buffIconPrefabPool; | 
|   | 
|     private GameObjectPoolManager.GameObjectPool buffLabelPrefabPool; | 
|   | 
|     public Transform damageNode; | 
|   | 
|     public Transform buffIconNode; | 
|   | 
|     public Transform buffLabelNode; | 
|   | 
|     private BattleField battleField; | 
|   | 
|     private List<DamageContent> damageContentList = new List<DamageContent>(); | 
|   | 
|     // 生命周期 | 
|     protected override void InitComponent() | 
|     { | 
|         base.InitComponent(); | 
|         // 初始化组件引用 绑定按钮等UI组件事件 | 
|     } | 
|   | 
|     protected override void OnPreOpen() | 
|     { | 
|         base.OnPreOpen(); | 
|         EventBroadcast.Instance.AddListener<string, BattleObject, List<long>>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); | 
|         EventBroadcast.Instance.AddListener<BattleObject, SkillConfig>(EventName.BATTLE_BUFF_MOUNTED, OnBuffMounted); | 
|         EventBroadcast.Instance.AddListener<BattleObject, SkillConfig>(EventName.BATTLE_BUFF_DISAPEAR, OnBuffDisapear); | 
|         damagePrefabPool = GameObjectPoolManager.Instance.RequestPool(UILoader.LoadPrefab("DamageContent")); | 
|         // buffIconPrefabPool = GameObjectPoolManager.Instance.RequestPool(); | 
|         // buffLabelPrefabPool = GameObjectPoolManager.Instance.RequestPool(ResManager.Instance.LoadAsset<GameObject>("UIComp", "BuffContent")); | 
|     } | 
|   | 
|     protected override void OnPreClose() | 
|     { | 
|         base.OnPreClose(); | 
|         EventBroadcast.Instance.RemoveListener<string, BattleObject, List<long>>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); | 
|         EventBroadcast.Instance.RemoveListener<BattleObject, SkillConfig>(EventName.BATTLE_BUFF_MOUNTED, OnBuffMounted); | 
|         EventBroadcast.Instance.RemoveListener<BattleObject, SkillConfig>(EventName.BATTLE_BUFF_DISAPEAR, OnBuffDisapear); | 
|     } | 
|   | 
|     protected override void OnOpen() | 
|     { | 
|         base.OnOpen(); | 
|     } | 
|   | 
|     protected override void OnClose() | 
|     { | 
|         base.OnClose(); | 
|         battleField.OnBattlePause -= OnBattlePause; | 
|         battleField = null; | 
|     } | 
|   | 
|     protected override void NextFrameAfterOpen() | 
|     { | 
|         base.NextFrameAfterOpen(); | 
|     } | 
|   | 
|     protected override void CompleteClose() | 
|     { | 
|         base.CompleteClose(); | 
|     } | 
|   | 
|     private void RemoveDamageContent(DamageContent content) | 
|     { | 
|         damageContentList.Remove(content); | 
|         damagePrefabPool.Release(content.gameObject); | 
|     } | 
|   | 
|     private void OnDamageTaken(string guid, BattleObject bo, List<long> damageList) | 
|     { | 
|         GameObject damageContent = damagePrefabPool.Request(); | 
|         DamageContent content = damageContent.GetComponent<DamageContent>(); | 
|         damageContent.transform.SetParent(damageNode, false); | 
|         damageContent.transform.localPosition = new Vector3(damageContent.transform.localPosition.x, damageContent.transform.localPosition.y, 0); | 
|         content.SetDamage(damageList, () => RemoveDamageContent(content)); | 
|         damageContentList.Add(content); | 
|   | 
|         // heroGo 的 parent 作为参考节点 | 
|   | 
|         var heroRect = bo.heroRectTrans; | 
|         if (heroRect == null) | 
|             return; | 
|   | 
|         // 计算 heroGo 在 content 父节点下的 anchoredPosition | 
|         var contentRect = content.GetComponent<RectTransform>(); | 
|         var contentParentRect = contentRect.parent as RectTransform; | 
|   | 
|         // 获取 heroGo 的世界坐标 | 
|         Vector3 worldTargetPos = heroRect.TransformPoint(heroRect.anchoredPosition); | 
|   | 
|         // 转换到 content 父节点下的 anchoredPosition | 
|         Vector2 anchoredPos; | 
|         RectTransformUtility.ScreenPointToLocalPointInRectangle( | 
|             contentParentRect, | 
|             RectTransformUtility.WorldToScreenPoint(null, worldTargetPos), | 
|             null, | 
|             out anchoredPos); | 
|   | 
|         contentRect.anchoredPosition = anchoredPos; | 
|     } | 
|   | 
|     private void OnBuffMounted(BattleObject bo, SkillConfig buffConfig) | 
|     { | 
|          | 
|     } | 
|   | 
|     private void OnBuffDisapear(BattleObject bo, SkillConfig buffConfig) | 
|     { | 
|   | 
|     } | 
|   | 
|     public void SetBattleField(BattleField _battleField) | 
|     { | 
|         if (battleField != null) | 
|         { | 
|             battleField.OnBattlePause -= OnBattlePause; | 
|         } | 
|   | 
|         battleField = _battleField; | 
|         battleField.OnBattlePause += OnBattlePause; | 
|     } | 
|   | 
|     private void OnBattlePause(bool isPause) | 
|     { | 
|         //  游戏暂停 | 
|         if (isPause) | 
|         { | 
|             foreach (var content in damageContentList) | 
|             { | 
|                 content.Stop(); | 
|             } | 
|         } | 
|         //  游戏恢复 | 
|         else | 
|         { | 
|             foreach (var content in damageContentList) | 
|             { | 
|                 content.Resume(); | 
|             } | 
|         } | 
|     } | 
| } |