|  |  |  | 
|---|
|  |  |  | using System.Collections.Generic; | 
|---|
|  |  |  | using LitJson; | 
|---|
|  |  |  | using UnityEngine; | 
|---|
|  |  |  | using UnityEngine.UI; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class ArenaBattleWin : UIBase | 
|---|
|  |  |  | public class ArenaBattleWin : BaseBattleWin | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // 组件引用 | 
|---|
|  |  |  | [SerializeField] Transform mountPoint; | 
|---|
|  |  |  | [SerializeField] Transform transButtons; | 
|---|
|  |  |  | [SerializeField] Button btnSpeed; | 
|---|
|  |  |  | [SerializeField] Text textSpeed; | 
|---|
|  |  |  | [SerializeField] Button btnPass; | 
|---|
|  |  |  | [SerializeField] Button btnPause; | 
|---|
|  |  |  | private BattleRootNode battleRootNode = null; | 
|---|
|  |  |  | private BattleField battleField; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] HeroCountryComponent myCountry; | 
|---|
|  |  |  | [SerializeField] TextEx txtMyLV; | 
|---|
|  |  |  | [SerializeField] TextEx txtMyName; | 
|---|
|  |  |  | 
|---|
|  |  |  | [SerializeField] AvatarCell enemyAvatarCell; | 
|---|
|  |  |  | [SerializeField] List<ArenaHeroHead> enemyHeroHeads; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] TextEx txtWaveInfo; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public TotalDamageDisplayer totalDamageDisplayer; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public SkillTips skillTipsRed; | 
|---|
|  |  |  | public SkillTips skillTipsBlue; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生命周期 | 
|---|
|  |  |  | protected override void InitComponent() | 
|---|
|  |  |  | protected override void RegisterBattleEvents() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.InitComponent(); | 
|---|
|  |  |  | // 初始化组件引用 绑定按钮等UI组件事件 | 
|---|
|  |  |  | btnSpeed.AddListener(ChangeSpeed); | 
|---|
|  |  |  | btnPass.AddListener(OnClickPass); | 
|---|
|  |  |  | btnPause.AddListener(OnClickPause); | 
|---|
|  |  |  | base.RegisterBattleEvents(); | 
|---|
|  |  |  | EventBroadcast.Instance.AddListener<string, JsonData>(EventName.BATTLE_END, OnBattleEnd); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnClickPause() | 
|---|
|  |  |  | protected override void UnregisterBattleEvents() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (null == battleField) | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | battleField.IsPause = !battleField.IsPause; | 
|---|
|  |  |  | base.UnregisterBattleEvents(); | 
|---|
|  |  |  | EventBroadcast.Instance.RemoveListener<string, JsonData>(EventName.BATTLE_END, OnBattleEnd); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnClickPass() | 
|---|
|  |  |  | protected virtual void OnBattleEnd(string guid, JsonData endData) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | if (battleField != null && guid == battleField.guid) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | DisplayHpInfo(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected override void OnPreOpen() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.OnPreOpen(); | 
|---|
|  |  |  | MainWin.TabChangeEvent += OnTabChangeEvent; | 
|---|
|  |  |  | BattleManager.Instance.onBattleFieldCreate += OnCreateBattleField; | 
|---|
|  |  |  | EventBroadcast.Instance.AddListener<BattleDmgInfo>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); | 
|---|
|  |  |  | EventBroadcast.Instance.AddListener<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, OnCastSkill); | 
|---|
|  |  |  | EventBroadcast.Instance.AddListener<string, JsonData>(EventName.BATTLE_END, OnBattleEnd); | 
|---|
|  |  |  | BattleManager.Instance.storyBattleField.IsPause = true; | 
|---|
|  |  |  | bool isOpenBattleChangeTab = IsOpenBattleChangeTab(); | 
|---|
|  |  |  | transButtons.localPosition = new Vector3(0, isOpenBattleChangeTab ? 130 : 0, 0); | 
|---|
|  |  |  | if (isOpenBattleChangeTab) | 
|---|
|  |  |  | 
|---|
|  |  |  | protected override void OnPreClose() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.OnPreClose(); | 
|---|
|  |  |  | UIManager.Instance.CloseWindow<BattleHUDWin>(); | 
|---|
|  |  |  | MainWin.TabChangeEvent -= OnTabChangeEvent; | 
|---|
|  |  |  | BattleManager.Instance.onBattleFieldCreate -= OnCreateBattleField; | 
|---|
|  |  |  | EventBroadcast.Instance.RemoveListener<BattleDmgInfo>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken); | 
|---|
|  |  |  | EventBroadcast.Instance.RemoveListener<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, OnCastSkill); | 
|---|
|  |  |  | EventBroadcast.Instance.RemoveListener<string, JsonData>(EventName.BATTLE_END, OnBattleEnd); | 
|---|
|  |  |  | BattleManager.Instance.storyBattleField.IsPause = false; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | bool isOpenBattleChangeTab = IsOpenBattleChangeTab(); | 
|---|
|  |  |  | if (isOpenBattleChangeTab) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | UIManager.Instance.CloseWindow<ArenaBattleWin>(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnBattleEnd(string guid, JsonData endData) | 
|---|
|  |  |  | protected override void OnDamageTaken(BattleDmgInfo damageInfo) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (battleField != null && guid == battleField.guid) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | DisplayHpInfo(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnDamageTaken(BattleDmgInfo damageInfo) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.OnDamageTaken(damageInfo); | 
|---|
|  |  |  | if (battleField == null) | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | if (damageInfo.battleFieldGuid == battleField.guid) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | DisplayHpInfo(); | 
|---|
|  |  |  | totalDamageDisplayer.SetDamage(damageInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnCreateBattleField(string arg1, BattleField field) | 
|---|
|  |  |  | protected override void OnCreateBattleField(string guid, BattleField field) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (field.GetType() == battleField.GetType()) | 
|---|
|  |  |  | if (field is ArenaBattleField) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SetBattleField(field); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected override void OnClose() | 
|---|
|  |  |  | protected override void RefreshSpecific() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.OnClose(); | 
|---|
|  |  |  | if (battleRootNode != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | battleRootNode.transform.SetParent(Launch.Instance.transform); | 
|---|
|  |  |  | battleRootNode.transform.localPosition = new Vector3(-10000, -10000, 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (battleField != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | battleField.OnRoundChange -= OnRoundChange; | 
|---|
|  |  |  | battleField = null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void SetBattleField(BattleField _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); | 
|---|
|  |  |  | textSpeed.text = (BattleManager.Instance.speedIndex + 1).ToString(); | 
|---|
|  |  |  | Refresh(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | battleField.OnRoundChange -= OnRoundChange; | 
|---|
|  |  |  | battleField.OnRoundChange += OnRoundChange; | 
|---|
|  |  |  | OnRoundChange(battleField.round, battleField.turnMax); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public override void Refresh() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | base.Refresh(); | 
|---|
|  |  |  | DisplayHpInfo(); | 
|---|
|  |  |  | DisplayPlayerInfo(); | 
|---|
|  |  |  | totalDamageDisplayer.SetActive(false); | 
|---|
|  |  |  | skillTipsBlue.SetActive(false); | 
|---|
|  |  |  | skillTipsRed.SetActive(false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnCastSkill(string guid, SkillConfig skillConfig, TeamHero teamHero) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (battleField == 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 DisplayHpInfo() | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void OnRoundChange(int round, int maxRound) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | txtWaveInfo.text = string.Format("{0}/{1}", round, maxRound); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | bool IsOpenBattleChangeTab() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return FuncOpen.Instance.IsFuncOpen(ArenaManager.Instance.BattleChangeTabFuncId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|