yyl
6 天以前 3bd7f56906e31e8fe0072108c9d4652707b51de8
Main/System/Battle/StoryBossBattleWin.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -11,7 +12,7 @@
    private BattleRootNode battleRootNode = null;
    private BattleField battleField;
    private StoryBossBattleField battleField;
    [SerializeField]
    private Button btnSpeed;
@@ -39,6 +40,10 @@
    public Text txtBattleRound;
    public TotalDamageDisplayer totalDamageDisplayer;
    private BattleObject bossBattleObject = null;
    [SerializeField] public List<BattleBuffCell> buffCells;
    // 生命周期
    protected override void InitComponent()
@@ -84,15 +89,20 @@
        base.OnPreOpen();
        // SetBattleField(BattleManager.Instance.storyBattleField);
        BattleManager.Instance.onBattleFieldCreate += OnCreateBattleField;
        EventBroadcast.Instance.AddListener<BattleDmgInfo>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken);
        UIManager.Instance.CloseWindow<MainWin>();
    }
    protected override void OnPreClose()
    {
        base.OnPreClose();
        UIManager.Instance.CloseWindow<BattleHUDWin>();
        BattleManager.Instance.onBattleFieldCreate -= OnCreateBattleField;
        EventBroadcast.Instance.RemoveListener<BattleDmgInfo>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken);
        UIManager.Instance.CloseWindow<BattleHUDWin>();
        if (!UIManager.Instance.IsOpened<MainWin>())
            UIManager.Instance.OpenWindow<MainWin>();
@@ -102,13 +112,67 @@
    {
        if (field.GetType() == battleField.GetType())
        {
            SetBattleField(field);
            SetBattleField(field as StoryBossBattleField);
        }
    }
    protected override void OnOpen()
    {
        base.OnOpen();
    }
    public override void Refresh()
    {
        base.Refresh();
        // bossLifeBar.SetBaseInfo(battleField);
        // skillWordCells;
        NPCLineupConfig lineupConfig = battleField.GetBossLineupConfig();
        bossBattleObject = battleField.FindBoss();
        DisplaySkillWordsList(lineupConfig);
        if (null != bossBattleObject)
        {
            TeamHero teamHero = bossBattleObject.teamHero;
            bossHeadCell.SetTeamHero(teamHero);
            txtBossName.text = teamHero.name;
            NPCConfig npcConfig = NPCConfig.Get(teamHero.NPCID);
            bossLifeBar.SetBaseInfo(Mathf.Max(1, npcConfig.LifeBarCount), (ulong)teamHero.curHp, (ulong)teamHero.maxHp);
        }
        else
        {
            bossHeadCell.SetTeamHero(null);
            txtBossName.text = string.Empty;
            bossLifeBar.SetBaseInfo(2, 2, 2);
            Debug.LogError("找不到boss");
        }
        txtBattleRound.text = string.Format("{0}/{1}", battleField.round, battleField.turnMax);
    }
    private void RefreshHP()
    {
        if (null != bossBattleObject)
        {
            TeamHero teamHero = bossBattleObject.teamHero;
            bossLifeBar.Show((ulong)teamHero.curHp, (ulong)teamHero.maxHp);
        }
    }
    private void OnDamageTaken(BattleDmgInfo info)
    {
        if (info.hurtObj.ObjID == bossBattleObject.ObjID)
        {
            // Update the boss's health bar
            RefreshHP();
        }
        totalDamageDisplayer.SetDamage(info);
    }
    protected override void OnClose()
@@ -134,7 +198,7 @@
        base.CompleteClose();
    }
    public void SetBattleField(BattleField _battleField)
    public void SetBattleField(StoryBossBattleField _battleField)
    {
        battleField = _battleField;
        if (battleRootNode != null)
@@ -160,6 +224,61 @@
        battleField.UpdateCanvas(canvas);
        buttonsAdjuster.SetSortingOrder(BattleConst.ActiveHeroActionSortingOrder);
        Refresh();
        textSpeed.text = (BattleManager.Instance.speedIndex + 1).ToString();
    }
    public void DisplaySkillWordsList(NPCLineupConfig lineUPConfig)
    {
        if (skillWordCells.IsNullOrEmpty())
            return;
        if (null == lineUPConfig)
            return;
        for (int i = 0; i < skillWordCells.Length; i++)
        {
            if (i < lineUPConfig.SkillIDExList.Length)
            {
                skillWordCells[i].SetActive(true);
                int skillID = lineUPConfig.SkillIDExList[i];
                skillWordCells[i].Init(skillID, () =>
                {
                    SmallTipWin.showText = Language.Get("SmallTipFomat", SkillConfig.Get(skillID)?.SkillName, SkillConfig.Get(skillID)?.Description);
                    SmallTipWin.worldPos = CameraManager.uiCamera.ScreenToWorldPoint(Input.mousePosition);
                    SmallTipWin.isDownShow = true;
                    UIManager.Instance.OpenWindow<SmallTipWin>();
                });
            }
            else
            {
                skillWordCells[i].SetActive(false);
            }
        }
    }
    public void RefreshBuff(List<HB428_tagSCBuffRefresh> datas)
    {
        if (buffCells.IsNullOrEmpty())
            return;
        for (int i = 0; i < buffCells.Count; i++)
        {
            if (i < datas.Count)
            {
                buffCells[i].SetActive(true);
                HB428_tagSCBuffRefresh buffData = datas[i];
                buffCells[i].Init(buffData, () =>
                {
                    //  点击buff图标 显示buff描述/当前身上所有buff
                });
            }
            else
            {
                buffCells[i].SetActive(false);
            }
        }
    }
}