91 lines
2.6 KiB
C#
91 lines
2.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PlayerBarItem : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image icon;
|
|
[SerializeField] private Button _button;
|
|
[SerializeField] private PlayerBar _playerBar;
|
|
[SerializeField] private BattleBarType _type;
|
|
|
|
private Action<int> _action;
|
|
|
|
private void Awake()
|
|
{
|
|
_button = GetComponent<Button>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
_button.onClick.AddListener(ButtonEvent);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
_button.onClick.RemoveListener(ButtonEvent);
|
|
}
|
|
|
|
public void ResetIcon(int id,PlayerBar bar,BattleBarType barType)
|
|
{
|
|
_playerBar = bar;
|
|
_type = barType;
|
|
if (id==0)
|
|
{
|
|
icon.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
icon.gameObject.SetActive(true);
|
|
var data = JsonTab.Instance.tables.Item.Get(id);
|
|
icon.sprite = AssetBundleManager.ins.Sprite(data.Icon, AtlasType.ItemIcon);
|
|
}
|
|
}
|
|
|
|
private void ButtonEvent()
|
|
{
|
|
var equipment=BattleManager.ins.BattleEquipments[_playerBar.Index];
|
|
switch (_type)
|
|
{
|
|
case BattleBarType.weaponBar:
|
|
equipment.weaponID = 0;
|
|
BattleManager.ins.SaveBattleData(_playerBar.Index, equipment);
|
|
break;
|
|
case BattleBarType.weaponBar2:
|
|
equipment.weapon2ID = 0;
|
|
BattleManager.ins.SaveBattleData(_playerBar.Index, equipment);
|
|
break;
|
|
case BattleBarType.armorBar:
|
|
equipment.armorID = 0;
|
|
BattleManager.ins.SaveBattleData(_playerBar.Index, equipment);
|
|
break;
|
|
case BattleBarType.audioUniversalBar:
|
|
equipment.audioUniversalID = 0;
|
|
BattleManager.ins.SaveBattleData(_playerBar.Index, equipment);
|
|
break;
|
|
case BattleBarType.audioWeaponBar:
|
|
equipment.audioWeaponID = 0;
|
|
BattleManager.ins.SaveBattleData(_playerBar.Index, equipment);
|
|
break;
|
|
case BattleBarType.audioWeaponBar2:
|
|
equipment.audioWeapon2ID = 0;
|
|
BattleManager.ins.SaveBattleData(_playerBar.Index, equipment);
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
UIMgr.ins.ResetBattleReadyPanel();
|
|
}
|
|
}
|
|
|
|
public enum BattleBarType
|
|
{
|
|
weaponBar,
|
|
weaponBar2,
|
|
armorBar,
|
|
audioUniversalBar,
|
|
audioWeaponBar,
|
|
audioWeaponBar2
|
|
} |