继续重构调整(UI)
- 引入 UniTask 和异步版本的 UIModule - 调整 Runtime/UIBase 和 Presentation 下的脚本命名空间到 SepCore.UI - 将原来的 5 层 UI 迁移到异步实现 - 规范各层的 UI 脚本命名
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using SepCore.Event;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class SelectRoleForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private GameObject _randomRoleCard = null;
|
||||
|
||||
[SerializeField] private GameObject _roleCard = null;
|
||||
|
||||
[SerializeField] private RolePropertyArea _propertyArea = null;
|
||||
|
||||
private SelectRoleContext _context = null;
|
||||
|
||||
private RoleItem[] _roleItems = null;
|
||||
|
||||
public void RefreshUI(SelectRoleContext context)
|
||||
{
|
||||
_context = context;
|
||||
|
||||
int itemIndex = 1, roleIndex = 0;
|
||||
while (itemIndex < _roleItems.Length)
|
||||
{
|
||||
if (roleIndex < _context.RoleItemContexts.Length)
|
||||
{
|
||||
_roleItems[itemIndex].OnInit(_context.RoleItemContexts[roleIndex]);
|
||||
_roleItems[itemIndex].gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_roleItems[itemIndex].gameObject.SetActive(false);
|
||||
_roleItems[itemIndex].OnReset();
|
||||
}
|
||||
|
||||
itemIndex++;
|
||||
roleIndex++;
|
||||
}
|
||||
|
||||
UpdateShowRole(_context.RolePropertyAreaContext);
|
||||
}
|
||||
|
||||
#region FSM
|
||||
|
||||
protected override void OnInit(object userData)
|
||||
{
|
||||
base.OnInit(userData);
|
||||
_roleItems = this.transform.GetComponentsInChildren<RoleItem>();
|
||||
}
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
if (userData is SelectRoleContext context)
|
||||
{
|
||||
RefreshUI(context);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("SelectRoleForm requires SelectRoleFormContext as userData.");
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
base.OnClose(isShutdown, userData);
|
||||
|
||||
_context = null;
|
||||
foreach (var item in _roleItems)
|
||||
{
|
||||
item.OnReset();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void UpdateShowRole(RolePropertyAreaContext propertyAreaContext)
|
||||
{
|
||||
if (propertyAreaContext == null)
|
||||
{
|
||||
_randomRoleCard.SetActive(true);
|
||||
_roleCard.SetActive(false);
|
||||
_propertyArea.OnReset();
|
||||
}
|
||||
else
|
||||
{
|
||||
_randomRoleCard.SetActive(false);
|
||||
_propertyArea.OnInit(propertyAreaContext);
|
||||
_roleCard.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReturnButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuSelectRoleReturnEventArgs.Create());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user