174 lines
4.3 KiB
C#
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
|
|
} |