CTT/Unity/Assets/HotfixView/Event/UI/AddBuffEvent.cs

57 lines
1.8 KiB
C#

using ET.EventType;
using FairyGUI;
using System;
using System.Collections.Generic;
namespace ET
{
public class AddBuffEvent : AEvent<RefreshBuff>
{
public override async ETTask Run(RefreshBuff args)
{
var zoneScene = args.zoneScene;
Unit unit = zoneScene.GetComponent<UnitComponent>().Get(args.unitId);
if (!unit)
{
Log.Error($"unit is null where id is {args.unitId}");
return;
}
GList list = null;
switch (unit.UnitType)
{
case UnitType.Player:
list = MainUI.ui.m_listBuff;
break;
case UnitType.TeamMember:
if(UpdateTeamHeadInfoEvent.TeamMemberHeadInfoDic.TryGetValue(unit.Id,out FUI_HeadInfoItem headInfoItem))
{
list = headInfoItem.m_listBuff;
}
break;
default:
break;
}
if (list == null) return;
list.RemoveChildrenToPool();
BuffComponent buffComponent = unit.GetComponent<BuffComponent>();
foreach (BuffStateInfo buff in buffComponent.buffList.Values)
{
try
{
GButton btn = list.AddItemFromPool().asButton;
btn.icon = UIPackage.GetItemURL(FUIPackage.Skill, buff.iconId);
btn.onClick.Set(() =>
{
TabHelper.OpenBuffUI(buff);
});
}
catch (Exception e)
{
Log.Error(e);
}
}
await ETTask.CompletedTask;
}
}
}