引入 UISerializationRoot 和 Item
- 完成 MenuForm 和 SelectRoleForm 的迁移
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user