|  |  |  | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using System.Collections.Generic; | 
|---|
|  |  |  | using System.Collections.Generic; | 
|---|
|  |  |  | using UnityEngine; | 
|---|
|  |  |  | using UnityEngine.UI; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class StoryBossBattleWin : UIBase | 
|---|
|  |  |  | public class StoryBossBattleWin : BaseBattleWin | 
|---|
|  |  |  | { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 组件引用 | 
|---|
|  |  |  | public Transform mountPoint; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private BattleRootNode battleRootNode = null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private StoryBossBattleField battleField; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] | 
|---|
|  |  |  | private Button btnSpeed; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] | 
|---|
|  |  |  | private Text textSpeed; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] | 
|---|
|  |  |  | private Button btnPass; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] | 
|---|
|  |  |  | private Button btnPause; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public BossLifeBar bossLifeBar; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] | 
|---|
|  |  |  | public SkillWordCell[] skillWordCells; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] | 
|---|
|  |  |  | public BossHeadCell bossHeadCell; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] | 
|---|
|  |  |  | public Text txtBossName; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Text txtBattleRound; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public TotalDamageDisplayer totalDamageDisplayer; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public SkillTips skillTipsRed; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public SkillTips skillTipsBlue; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private BattleObject bossBattleObject = null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] public List<BattleBuffCell> buffCells; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生命周期 | 
|---|
|  |  |  | protected override void InitComponent() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.InitComponent(); | 
|---|
|  |  |  | // 初始化组件引用 绑定按钮等UI组件事件 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | btnSpeed.AddListener(ChangeSpeed); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | btnPass.AddListener(OnClickPass); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | btnPause.AddListener(OnClickPause); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnClickPause() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (null == battleField) | 
|---|
|  |  |  | return; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | battleField.IsPause = !battleField.IsPause; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnClickPass() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (null == battleField) | 
|---|
|  |  |  | return; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | battleField.ForceFinish(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void ChangeSpeed() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (null == battleField) | 
|---|
|  |  |  | return; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BattleManager.Instance.speedIndex = (BattleManager.Instance.speedIndex + 1) % BattleManager.Instance.speedGear.Length; | 
|---|
|  |  |  | battleField.SetSpeedRatio(BattleManager.Instance.speedGear[BattleManager.Instance.speedIndex]); | 
|---|
|  |  |  | textSpeed.text = (BattleManager.Instance.speedIndex + 1).ToString(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected override void OnPreOpen() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.OnPreOpen(); | 
|---|
|  |  |  | // SetBattleField(BattleManager.Instance.storyBattleField); | 
|---|
|  |  |  | BattleManager.Instance.onBattleFieldCreate += OnCreateBattleField; | 
|---|
|  |  |  | EventBroadcast.Instance.AddListener<BattleDmgInfo>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); | 
|---|
|  |  |  | EventBroadcast.Instance.AddListener<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, OnCastSkill); | 
|---|
|  |  |  | BattleManager.Instance.storyBattleField.IsPause = true; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | UIManager.Instance.CloseWindow<MainWin>(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected override void OnPreClose() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.OnPreClose(); | 
|---|
|  |  |  | BattleManager.Instance.onBattleFieldCreate -= OnCreateBattleField; | 
|---|
|  |  |  | EventBroadcast.Instance.RemoveListener<BattleDmgInfo>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); | 
|---|
|  |  |  | EventBroadcast.Instance.RemoveListener<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, OnCastSkill); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | UIManager.Instance.CloseWindow<BattleHUDWin>(); | 
|---|
|  |  |  | BattleManager.Instance.storyBattleField.IsPause = false; | 
|---|
|  |  |  | if (!UIManager.Instance.IsOpened<MainWin>()) | 
|---|
|  |  |  | UIManager.Instance.OpenWindow<MainWin>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | bossBattleObject.buffMgr.onBuffChanged -= OnBuffChanged; | 
|---|
|  |  |  | bossBattleObject = null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (battleField != null) | 
|---|
|  |  |  | protected override void OnCreateBattleField(string guid, BattleField field) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (field is StoryBossBattleField) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | battleField.OnRoundChange -= OnRoundChange; | 
|---|
|  |  |  | battleField = null; | 
|---|
|  |  |  | SetBattleField(field); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnCastSkill(string guid, SkillConfig skillConfig, TeamHero teamHero) | 
|---|
|  |  |  | protected override void RefreshSpecific() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (battleField == null) | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | StoryBossBattleField storyBossField = battleField as StoryBossBattleField; | 
|---|
|  |  |  | if (storyBossField == null) return; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (battleField.guid != guid) | 
|---|
|  |  |  | return; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BattleObject battleObject = battleField.battleObjMgr.GetBattleObject(teamHero.ObjID); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | bool isRed = battleObject.Camp == BattleCamp.Red; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SkillTips tips = isRed ? skillTipsRed : skillTipsBlue; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | tips.PlayMotion(battleField, isRed, teamHero, skillConfig); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnCreateBattleField(string arg1, BattleField field) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (field.GetType() == battleField.GetType()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SetBattleField(field as StoryBossBattleField); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected override void OnOpen() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.OnOpen(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public override void Refresh() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.Refresh(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // bossLifeBar.SetBaseInfo(battleField); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // skillWordCells; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | NPCLineupConfig lineupConfig = battleField.GetBossLineupConfig(); | 
|---|
|  |  |  | NPCLineupConfig lineupConfig = storyBossField.GetBossLineupConfig(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (null != bossBattleObject) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | bossBattleObject = null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | bossBattleObject = battleField.FindBoss(); | 
|---|
|  |  |  | bossBattleObject = storyBossField.FindBoss(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DisplaySkillWordsList(lineupConfig); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | Debug.LogError("找不到boss"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OnRoundChange(battleField.round, battleField.turnMax); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OnRoundChange(battleField.round, battleField.turnMax); // 确保回合显示被调用 | 
|---|
|  |  |  | OnBuffChanged(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | totalDamageDisplayer.SetActive(false); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | skillTipsBlue.SetActive(false); | 
|---|
|  |  |  | skillTipsRed.SetActive(false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnBuffChanged() | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnDamageTaken(BattleDmgInfo info) | 
|---|
|  |  |  | protected override void OnDamageTaken(BattleDmgInfo info) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (info.battleFieldGuid != battleField.guid) | 
|---|
|  |  |  | base.OnDamageTaken(info); | 
|---|
|  |  |  | if (battleField == null || info.battleFieldGuid != battleField.guid) | 
|---|
|  |  |  | return; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (info.hurtObj.ObjID == bossBattleObject.ObjID) | 
|---|
|  |  |  | if (bossBattleObject != null && info.hurtObj.ObjID == bossBattleObject.ObjID) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // Update the boss's health bar | 
|---|
|  |  |  | RefreshHP(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | totalDamageDisplayer.SetDamage(info); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected override void OnClose() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.OnClose(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (battleRootNode != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | battleRootNode.transform.SetParent(Launch.Instance.transform); | 
|---|
|  |  |  | battleRootNode.transform.localPosition = new Vector3(-10000, -10000, 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | battleField = null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected override void NextFrameAfterOpen() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.NextFrameAfterOpen(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected override void CompleteClose() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.CompleteClose(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void SetBattleField(StoryBossBattleField _battleField) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (battleField != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | battleField.OnRoundChange -= OnRoundChange; | 
|---|
|  |  |  | battleField = null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | battleField = _battleField; | 
|---|
|  |  |  | if (battleRootNode != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | battleRootNode.transform.localPosition = Vector3.zero; | 
|---|
|  |  |  | battleRootNode.transform.SetParent(Launch.Instance.transform); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | battleRootNode = battleField.battleRootNode; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | battleRootNode.transform.SetParent(mountPoint); | 
|---|
|  |  |  | battleRootNode.transform.localPosition = Vector3.zero; | 
|---|
|  |  |  | battleRootNode.transform.localScale = Vector3.one; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BattleHUDWin ui = UIManager.Instance.GetUI<BattleHUDWin>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (null == ui) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | ui = UIManager.Instance.OpenWindow<BattleHUDWin>(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ui.SetBattleField(battleField); | 
|---|
|  |  |  | battleField.UpdateCanvas(canvas); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Refresh(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | battleField.OnRoundChange -= OnRoundChange; | 
|---|
|  |  |  | battleField.OnRoundChange += OnRoundChange; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | textSpeed.text = (BattleManager.Instance.speedIndex + 1).ToString(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void DisplaySkillWordsList(NPCLineupConfig lineUPConfig) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnRoundChange(int round, int maxRound) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | txtBattleRound.text = string.Format("{0}/{1}", round, maxRound); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|