60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using SepCore.AsyncTask;
|
|
using SepCore.Event;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace SepCore.UI
|
|
{
|
|
public class RoleItem : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image _roleImage = null;
|
|
|
|
private RoleItemContext _context = null;
|
|
|
|
private bool _listenersBound;
|
|
|
|
public async UniTaskVoid OnInit(RoleItemContext context)
|
|
{
|
|
EnsureListeners();
|
|
|
|
_context = context;
|
|
if (string.IsNullOrEmpty(_context.IconName))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_roleImage.sprite = await SpriteLoader.LoadSpriteByKeyAsync(_context.IconName);
|
|
}
|
|
|
|
public void OnReset()
|
|
{
|
|
_context = null;
|
|
}
|
|
|
|
private void EnsureListeners()
|
|
{
|
|
if (_listenersBound)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_listenersBound = true;
|
|
|
|
CommonButton button = GetComponent<CommonButton>();
|
|
button.onClick.AddListener(OnConfirmRoleClick);
|
|
button.RegisterPointerEnterAction(OnHoverEnter);
|
|
}
|
|
|
|
private void OnHoverEnter()
|
|
{
|
|
GameEntry.Event.Fire(this, SelectRoleHoverEventArgs.Create(_context.RoleName));
|
|
}
|
|
|
|
private void OnConfirmRoleClick()
|
|
{
|
|
GameEntry.Event.Fire(this, SelectRoleConfirmEventArgs.Create());
|
|
}
|
|
}
|
|
}
|