2024-12-07 22:30:19 +08:00
|
|
|
using System;
|
2024-12-04 17:26:27 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2024-12-13 20:38:15 +08:00
|
|
|
using TMPro;
|
2024-12-04 17:26:27 +08:00
|
|
|
using UnityEngine;
|
2024-12-07 22:30:19 +08:00
|
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
|
|
/// 战斗界面
|
|
|
|
/// </summary>
|
2024-12-04 17:26:27 +08:00
|
|
|
public class BattlePanel : MonoBehaviour
|
|
|
|
{
|
2024-12-07 22:30:19 +08:00
|
|
|
|
|
|
|
[SerializeField] private GameObject levelPanel;
|
|
|
|
[SerializeField] private GameObject readyPanel;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] private UIBattleItem _battleItem;
|
|
|
|
[SerializeField] private Transform _battleParent;
|
|
|
|
[SerializeField] private Transform itemParent;
|
2024-12-13 20:38:15 +08:00
|
|
|
[SerializeField] private TextMeshProUGUI _hpText;
|
|
|
|
[SerializeField] private TextMeshProUGUI _attackText;
|
2024-12-22 20:35:00 +08:00
|
|
|
[SerializeField] private Text name;
|
|
|
|
[SerializeField] private Image backImage;
|
2024-12-07 22:30:19 +08:00
|
|
|
|
|
|
|
[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;
|
2024-12-20 18:51:07 +08:00
|
|
|
[SerializeField] private int levelID = 0;
|
|
|
|
|
2024-12-22 20:35:00 +08:00
|
|
|
[SerializeField] private Text _goldNum;
|
|
|
|
[SerializeField] private Text _diamondNum;
|
|
|
|
[SerializeField] private Text _physicalNum;
|
|
|
|
|
2024-12-07 22:30:19 +08:00
|
|
|
#region 生命周期
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-04 17:26:27 +08:00
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-12-07 22:30:19 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-12-04 17:26:27 +08:00
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2024-12-07 22:30:19 +08:00
|
|
|
|
|
|
|
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 准备界面
|
2024-12-20 18:51:07 +08:00
|
|
|
|
2024-12-22 20:35:00 +08:00
|
|
|
public void ResetLevelID()
|
2024-12-20 18:51:07 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2024-12-21 14:05:40 +08:00
|
|
|
DataManager.SetNowLevel(levelID);
|
2024-12-22 20:35:00 +08:00
|
|
|
OpenLevel();
|
|
|
|
}
|
|
|
|
public void OpenLevel()
|
|
|
|
{
|
|
|
|
|
|
|
|
BDebug.Log(levelID);
|
|
|
|
name.text = JsonTab.Instance.tables.Level.Get(DataManager.GetNowLevel()).Name;
|
|
|
|
backImage.sprite = AssetBundleManager.ins.Sprite(
|
|
|
|
JsonTab.Instance.tables.Level.Get(DataManager.GetNowLevel()).Levelicon, AtlasType.AtlasBattleBack);
|
|
|
|
ResetGold();
|
|
|
|
|
2024-12-20 18:51:07 +08:00
|
|
|
}
|
2024-12-07 22:30:19 +08:00
|
|
|
private void OpenCombatPanel()
|
|
|
|
{
|
2024-12-22 20:35:00 +08:00
|
|
|
if (DataManager.GetPhysical()>=5)
|
2024-12-07 22:30:19 +08:00
|
|
|
{
|
2024-12-22 20:35:00 +08:00
|
|
|
DataManager.RemovePhysical();
|
|
|
|
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();
|
2024-12-07 22:30:19 +08:00
|
|
|
}
|
2024-12-13 20:38:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
2024-12-07 22:30:19 +08:00
|
|
|
}
|
|
|
|
public void ResetReadyPanel()
|
|
|
|
{
|
|
|
|
foreach (var pBar in _playerBars)
|
|
|
|
{
|
2024-12-13 20:38:15 +08:00
|
|
|
pBar.RestData(this);
|
2024-12-07 22:30:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var itemBar in _list)
|
|
|
|
{
|
|
|
|
itemBar.ResetText();
|
|
|
|
}
|
2024-12-11 20:35:20 +08:00
|
|
|
openSoldier.gameObject.SetActive(!BattleManager.ins.OpenVideoSoldier);
|
|
|
|
openWeaponry.gameObject.SetActive(!BattleManager.ins.OpenVideoWeaponry);
|
2024-12-13 20:38:15 +08:00
|
|
|
int h = 0;
|
|
|
|
int a = 0;
|
|
|
|
BattleManager.ins.GetAttribute(ref h, ref a);
|
|
|
|
_hpText.text = h.ToString();
|
|
|
|
_attackText.text = a.ToString();
|
2024-12-07 22:30:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2024-12-13 20:38:15 +08:00
|
|
|
if (JsonTab.Instance.tables.Item.Get(dicData.Key).Includearms!=0&&DataManager.GetItem(dicData.Key)>0)
|
2024-12-07 22:30:19 +08:00
|
|
|
{
|
|
|
|
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);
|
2024-12-11 20:35:20 +08:00
|
|
|
openItemParent.gameObject.SetActive(false);
|
|
|
|
closeItemParent.gameObject.SetActive(true);
|
2024-12-07 22:30:19 +08:00
|
|
|
}
|
|
|
|
private void CloseItemPanel()
|
|
|
|
{
|
|
|
|
itemParent.gameObject.SetActive(false);
|
2024-12-11 20:35:20 +08:00
|
|
|
openItemParent.gameObject.SetActive(true);
|
|
|
|
closeItemParent.gameObject.SetActive(false);
|
2024-12-07 22:30:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void StartBattle()
|
|
|
|
{
|
2024-12-13 20:38:15 +08:00
|
|
|
if (BattleManager.ins.BattleStart())
|
|
|
|
{
|
|
|
|
BattleManager.ins.StartBattle();
|
|
|
|
}
|
2024-12-07 22:30:19 +08:00
|
|
|
}
|
2024-12-22 20:35:00 +08:00
|
|
|
public void ResetGold()
|
|
|
|
{
|
|
|
|
_goldNum.text = DataManager.GetItem(2).ToString();
|
|
|
|
_diamondNum.text = DataManager.GetItem(3).ToString();
|
|
|
|
_physicalNum.text=DataManager.GetPhysical().ToString();
|
|
|
|
}
|
2024-12-07 22:30:19 +08:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 视频事件
|
|
|
|
|
|
|
|
private void OpenVideoWeaponryEvent()
|
|
|
|
{
|
|
|
|
BattleManager.ins.OpenVideoWeaponryEvent();
|
|
|
|
ResetReadyPanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OpenVideoSoldierEvent()
|
|
|
|
{
|
|
|
|
BattleManager.ins.OpenVideoSoldierEvent();
|
|
|
|
ResetReadyPanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|