按 5 层 UI 规范的 §3.5(View 只消费 Context、不内嵌业务/数据筛选) 对 SelectRoleForm 视图侧做一轮收敛,顺带把"随机角色卡"与"角色槽"在结构层面分离,让 prefab 不再依赖 GetComponentsInChildren 顺序来跳过随机卡上的 RoleItem 占位。 RoleItem: - UpdateShowRole() → OnHoverEnter()。原方法名与 Form/Controller 上曾经存在的 UpdateShowRole 同名,但语义完全不同(后者是切换属性卡显示,这里是上报 hover 事件),改名消除歧义,与 prefab 上 PointerEnter 绑定的实际语义对齐。 - 补 _context == null 早退,不再把 RoleId = -1 的"伪 hover"上报到下游、依赖 UseCase 端的哨兵兜底。 SelectRoleForm: - 新增 OnRandomConfirmClick(),给随机角色卡的 CommonButton 提供独立的 Click 入口,直接发 SelectRoleConfirmEventArgs,不再借 RoleItem.OnConfirmRoleClick 这条路径。 - RefreshUI 由 while + 双下标(itemIndex / roleIndex 同步推进、itemIndex 起步为 1 跳过随机卡上的 RoleItem 占位)收成单下标 for,起步下标恢复 0;槽位不足时 OnReset 放在 SetActive(false) 之前,语义顺序更自然。 - 清掉未使用的 using System。
46 lines
1.0 KiB
C#
46 lines
1.0 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using SepCore.Event;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace SepCore.UI
|
|
{
|
|
public class RoleItem : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image _roleImage = null;
|
|
|
|
private RoleItemContext _context = null;
|
|
|
|
public async UniTaskVoid OnInit(RoleItemContext context)
|
|
{
|
|
_context = context;
|
|
if (_context == null || string.IsNullOrEmpty(_context.IconName))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_roleImage.sprite = await GameEntry.SpriteCache.GetSprite(_context.IconName);
|
|
}
|
|
|
|
public void OnReset()
|
|
{
|
|
_context = null;
|
|
}
|
|
|
|
public void OnHoverEnter()
|
|
{
|
|
if (_context == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GameEntry.Event.Fire(this, SelectRoleHoverEventArgs.Create(_context.RoleId));
|
|
}
|
|
|
|
public void OnConfirmRoleClick()
|
|
{
|
|
GameEntry.Event.Fire(this, SelectRoleConfirmEventArgs.Create());
|
|
}
|
|
}
|
|
}
|