CTT/Unity/Assets/HotfixView/Numeric/NumericWatcher_SkinId.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2021-06-29 11:28:15 +08:00
using Cal.DataTable;
using ET;
2021-04-08 20:09:59 +08:00
namespace ET
{
[NumericWatcher(NumericType.SkinId)]
public class NumericWatcher_SkinId : INumericWatcher
{
public async ETTask Run(Entity entity, float old, float value)
{
Log.Info($"@{entity.Id}改变 SkinId:{old} -> {value}");
2021-04-11 19:50:39 +08:00
Unit unit = entity.As<Unit>();
2021-04-08 20:09:59 +08:00
int skinId = MathHelper.RoundToInt(value);
if (skinId == 0)
{
Log.Error($"skinId == 0 where id = {unit.Id}");
return;
}
2021-06-29 11:28:15 +08:00
long id = unit.Id;
if (!unit)
2021-04-08 20:09:59 +08:00
{
2021-06-29 11:28:15 +08:00
Log.Error($"unit is invalid where id = {id}");
return;
}
SkinBase skinBase =SkinBaseCategory.Instance.Get(skinId);
if (skinBase == null)
{
Log.Error($"没有skinId = {skinId}");
return;
}
UnitView unitView = unit.GetComponent<UnitView>();
if (unitView)
{
await unitView.ChangeSkin(skinBase.PrfabId);
}
2021-04-08 20:09:59 +08:00
unit.RefreshPosition();
await ETTask.CompletedTask;
}
}
}