WXGame/Blacksmith/Assets/Script/UI/BattlePanel.cs
2024-12-11 20:35:20 +08:00

174 lines
4.3 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 战斗界面
/// </summary>
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 List<PlayerBar> _playerBars;
[SerializeField] private List<UIBattleItem> _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;
#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
private void OpenCombatPanel()
{
readyPanel.SetActive(true);
UIMgr.ins.CloseSwithPanel();
BattleManager.ins.ResetBattleData();
ResetItem();
foreach (var playerBar in _playerBars)
{
playerBar.RestData();
}
OpenItemPanel();
}
public void ResetReadyPanel()
{
foreach (var pBar in _playerBars)
{
pBar.RestData();
}
foreach (var itemBar in _list)
{
itemBar.ResetText();
}
openSoldier.gameObject.SetActive(!BattleManager.ins.OpenVideoSoldier);
openWeaponry.gameObject.SetActive(!BattleManager.ins.OpenVideoWeaponry);
}
private void ResetItem()
{
if (_list==null)
{
_list = new List<UIBattleItem>();
}
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)
{
var obj = Instantiate(_battleItem.gameObject, _battleParent);
obj.SetActive(true);
_list.Add(obj.GetComponent<UIBattleItem>());
obj.GetComponent<UIBattleItem>().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()
{
BattleManager.ins.StartBattle();
}
#endregion
#region
private void OpenVideoWeaponryEvent()
{
BattleManager.ins.OpenVideoWeaponryEvent();
ResetReadyPanel();
}
private void OpenVideoSoldierEvent()
{
BattleManager.ins.OpenVideoSoldierEvent();
ResetReadyPanel();
}
#endregion
}