Files
test/Assets/PerfectWorld/Scripts/UI/GamePlay/SkillUI/Widget/SkillSlotWidget.cs
T
2026-04-14 12:22:02 +07:00

66 lines
1.6 KiB
C#

using System;
using BrewMonster.Assets.PerfectWorld.Scripts.UI.GamePlay;
using UnityEngine;
using UnityEngine.UI;
namespace BrewMonster
{
public enum SkillSlotType
{
Normal= 0,
AddSkill
}
public class SkillSlotWidget : AUIImagePictureBase
{
[SerializeField] private SkillSlotType _skillSlotType;
[SerializeField] private Image _backgroundImage;
[SerializeField] private Button _button;
[SerializeField] private Sprite[] _slotBackgrounds;
[SerializeField] private GameObject _focusFrame;
private int _skillId;
public int SkillId => _skillId;
public event Action<SkillSlotWidget> OnClickedSkillSlot;
private void OnValidate()
{
var index = (int)_skillSlotType;
if (index < 0 || index >= _slotBackgrounds.Length)
{
BMLogger.LogError("Invalid skill slot type");
}
else
{
if(_backgroundImage == null) return;
_backgroundImage.sprite = _slotBackgrounds[index];
}
}
private void OnEnable()
{
_button.onClick.AddListener(OnClickedButton);
}
private void OnDisable()
{
_button.onClick.RemoveListener(OnClickedButton);
}
private void OnClickedButton()
{
OnClickedSkillSlot?.Invoke(this);
}
public void SetSkillId(int skillId)
{
_skillId = skillId;
}
public void SetFocusFrame(bool isFocus)
{
_focusFrame.SetActive(isFocus);
}
}
}