using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; /// /// 战斗界面 /// public class BattlePanel : MonoBehaviour { [SerializeField] private GameObject levelPanel; [SerializeField] private GameObject readyPanel; [SerializeField] private UIBattleItem _battleItem; [SerializeField] private Transform _battleParent; [SerializeField] private Transform itemParent; [SerializeField] private TextMeshProUGUI _hpText; [SerializeField] private TextMeshProUGUI _attackText; [SerializeField] private List _playerBars; [SerializeField] private List _list; [SerializeField] private Button battleButton; [SerializeField] private Button openItemParent; [SerializeField] private Button closeItemParent; [SerializeField] private Button openWeaponry; [SerializeField] private Button openSoldier; [SerializeField] private Button startButton; [SerializeField] private int levelID = 0; #region 生命周期 // Start is called before the first frame update void Start() { } private void OnEnable() { battleButton.onClick.AddListener(OpenCombatPanel); openWeaponry.onClick.AddListener(OpenVideoWeaponryEvent); openSoldier.onClick.AddListener(OpenVideoSoldierEvent); openItemParent.onClick.AddListener(OpenItemPanel); closeItemParent.onClick.AddListener(CloseItemPanel); startButton.onClick.AddListener(StartBattle); readyPanel.SetActive(false); } // Update is called once per frame void Update() { } private void OnDestroy() { battleButton.onClick.RemoveListener(OpenCombatPanel); openWeaponry.onClick.RemoveListener(OpenVideoWeaponryEvent); openSoldier.onClick.RemoveListener(OpenVideoSoldierEvent); openItemParent.onClick.RemoveListener(OpenItemPanel); closeItemParent.onClick.RemoveListener(CloseItemPanel); startButton.onClick.RemoveListener(StartBattle); } #endregion #region 战斗界面 private void InitLevelPanel() { } #endregion #region 准备界面 public void OpenLevel() { for (int i = 0; i < JsonTab.Instance.tables.Level.DataList.Count; i++) { if (DataManager.GetLevelLock(JsonTab.Instance.tables.Level.DataList[i].ID)) { levelID = JsonTab.Instance.tables.Level.DataList[i].ID; } } DataManager.SetNowLevel(levelID); } private void OpenCombatPanel() { readyPanel.SetActive(true); UIMgr.ins.CloseSwithPanel(); BattleManager.ins.ResetBattleData(); ResetItem(); foreach (var playerBar in _playerBars) { playerBar.RestData(this); } OpenItemPanel(); ResetReadyPanel(); int h = 0; int a = 0; BattleManager.ins.GetAttribute(ref h, ref a); _hpText.text = h.ToString(); _attackText.text = a.ToString(); } public void SetPlayerIndex() { foreach (var pBar in _playerBars) { pBar.ResetBack(); } int h = 0; int a = 0; BattleManager.ins.GetAttribute(ref h, ref a); _hpText.text = h.ToString(); _attackText.text = a.ToString(); } public void ResetReadyPanel() { foreach (var pBar in _playerBars) { pBar.RestData(this); } foreach (var itemBar in _list) { itemBar.ResetText(); } openSoldier.gameObject.SetActive(!BattleManager.ins.OpenVideoSoldier); openWeaponry.gameObject.SetActive(!BattleManager.ins.OpenVideoWeaponry); int h = 0; int a = 0; BattleManager.ins.GetAttribute(ref h, ref a); _hpText.text = h.ToString(); _attackText.text = a.ToString(); } private void ResetItem() { if (_list==null) { _list = new List(); } if (_list.Count != 0) { for (int i = 0; i < _list.Count; i++) { Destroy(_list[i].gameObject); } _list.Clear(); } var dic = DataManager.ItemDictionary; foreach (var dicData in dic) { if (JsonTab.Instance.tables.Item.Get(dicData.Key).Includearms!=0&&DataManager.GetItem(dicData.Key)>0) { var obj = Instantiate(_battleItem.gameObject, _battleParent); obj.SetActive(true); _list.Add(obj.GetComponent()); obj.GetComponent().ResetData(dicData.Key); } } } private void OpenItemPanel() { itemParent.gameObject.SetActive(true); openItemParent.gameObject.SetActive(false); closeItemParent.gameObject.SetActive(true); } private void CloseItemPanel() { itemParent.gameObject.SetActive(false); openItemParent.gameObject.SetActive(true); closeItemParent.gameObject.SetActive(false); } private void StartBattle() { if (BattleManager.ins.BattleStart()) { BattleManager.ins.StartBattle(); } } #endregion #region 视频事件 private void OpenVideoWeaponryEvent() { BattleManager.ins.OpenVideoWeaponryEvent(); ResetReadyPanel(); } private void OpenVideoSoldierEvent() { BattleManager.ins.OpenVideoSoldierEvent(); ResetReadyPanel(); } #endregion }