| | |
| | | using System; |
| | | using LitJson; |
| | | |
| | | |
| | | // 这个界面是 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() |
| | |
| | | EventBroadcast.Instance.AddListener<BattleDmgInfo>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); |
| | | EventBroadcast.Instance.AddListener<string, JsonData>(EventName.BATTLE_END, OnBattleEnd); |
| | | damagePrefabPool = GameObjectPoolManager.Instance.RequestPool(UILoader.LoadPrefab("DamageContent")); |
| | | // buffIconPrefabPool = GameObjectPoolManager.Instance.RequestPool(); |
| | | // buffLabelPrefabPool = GameObjectPoolManager.Instance.RequestPool(ResManager.Instance.LoadAsset<GameObject>("UIComp", "BuffContent")); |
| | | } |
| | | |
| | | private void OnBattleEnd(string guid, JsonData data) |
| | |
| | | protected override void OnClose() |
| | | { |
| | | base.OnClose(); |
| | | if (battleField != null) |
| | | { |
| | | battleField.OnBattlePause -= OnBattlePause; |
| | | battleField.OnBattleRun -= OnBattleRun; |
| | | battleField.OnSpeedRatioChange -= OnSpeedRatioChange; |
| | | battleField = null; |
| | | } |
| | | } |
| | | |
| | | protected override void NextFrameAfterOpen() |
| | |
| | | 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(damageInfo, () => RemoveDamageContent(content)); |
| | | damageContentList.Add(content); |
| | | |
| | | var heroRect = damageInfo.hurtObj.heroRectTrans; |
| | | if (heroRect == null) |
| | | { |
| | | damagePrefabPool.Release(damageContent); |
| | | return; |
| | | } |
| | | |
| | | var contentRect = content.GetComponent<RectTransform>(); |
| | | var contentParentRect = contentRect.parent as RectTransform; |
| | |
| | | null, |
| | | out anchoredPos); |
| | | |
| | | contentRect.anchoredPosition = anchoredPos; |
| | | // 设置初始位置和结束位置 |
| | | content.beginPos = anchoredPos; |
| | | content.endPos = anchoredPos + new Vector2(0, 150); |
| | | |
| | | // 设置速度比例 |
| | | if (battleField != null) |
| | | { |
| | | content.SetRatio(battleField.speedRatio, 1f); |
| | | } |
| | | |
| | | // 设置伤害数据并开始播放 |
| | | content.SetDamage(damageInfo, () => RemoveDamageContent(content)); |
| | | damageContentList.Add(content); |
| | | } |
| | | |
| | | public void SetBattleField(BattleField _battleField) |
| | |
| | | if (battleField != null) |
| | | { |
| | | battleField.OnBattlePause -= OnBattlePause; |
| | | battleField.OnBattleRun -= OnBattleRun; |
| | | battleField.OnSpeedRatioChange -= OnSpeedRatioChange; |
| | | } |
| | | ClearContent(string.Empty, true); |
| | | battleField = _battleField; |
| | | battleField.OnBattlePause += OnBattlePause; |
| | | battleField.OnBattleRun += OnBattleRun; |
| | | battleField.OnSpeedRatioChange += OnSpeedRatioChange; |
| | | } |
| | | |
| | | private void OnSpeedRatioChange(float newSpeedRatio) |
| | | { |
| | | foreach (var content in damageContentList) |
| | | { |
| | | content.SetRatio(newSpeedRatio, 1f); |
| | | } |
| | | } |
| | | |
| | | private void OnBattlePause(bool isPause) |
| | | { |
| | | // 游戏暂停 |
| | | if (isPause) |
| | | { |
| | | foreach (var content in damageContentList) |
| | |
| | | content.Stop(); |
| | | } |
| | | } |
| | | // 游戏恢复 |
| | | else |
| | | { |
| | | foreach (var content in damageContentList) |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void OnBattleRun() |
| | | { |
| | | for (int i = damageContentList.Count - 1; i >= 0; i--) |
| | | { |
| | | if (i < damageContentList.Count) |
| | | { |
| | | damageContentList[i].Run(); |
| | | } |
| | | } |
| | | } |
| | | } |