zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/HotfixView/Event/UI/AddBuffEvent.cs

56 lines
1.7 KiB
C#
Raw Normal View History

2021-04-10 19:49:32 +08:00
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 unit = UnitComponent.Instance.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 var headInfoItem))
{
list = headInfoItem.m_listBuff;
}
break;
default:
break;
}
if (list == null) return;
list.RemoveChildrenToPool();
BuffComponent buffComponent = unit.GetComponent<BuffComponent>();
foreach (var buff in buffComponent.buffList.Values)
{
try
{
var btn = list.AddItemFromPool().asButton;
btn.icon = UIPackage.GetItemURL(FUIPackage.Bag, buff.iconId.ToString());
btn.onClick.Set(() =>
{
TabHelper.OpenBuffUI(buff);
});
}
catch (Exception e)
{
Log.Error(e);
}
}
await ETTask.CompletedTask;
}
}
}