41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using Cal.DataTable;
|
|
using ET;
|
|
|
|
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}");
|
|
Unit unit = entity.As<Unit>();
|
|
int skinId = MathHelper.RoundToInt(value);
|
|
if (skinId == 0)
|
|
{
|
|
Log.Error($"skinId == 0 where id = {unit.Id}");
|
|
return;
|
|
}
|
|
long id = unit.Id;
|
|
if (!unit)
|
|
{
|
|
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);
|
|
}
|
|
unit.RefreshPosition();
|
|
await ETTask.CompletedTask;
|
|
}
|
|
}
|
|
}
|