mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using System.Collections.Generic;
|
||
using Unity.Mathematics;
|
||
|
||
namespace ET.Server
|
||
{
|
||
[FriendOf(typeof(MoveComponent))]
|
||
[FriendOf(typeof(NumericComponent))]
|
||
public static partial class UnitHelper
|
||
{
|
||
public static UnitInfo CreateUnitInfo(Unit unit)
|
||
{
|
||
UnitInfo unitInfo = new();
|
||
NumericComponent nc = unit.GetComponent<NumericComponent>();
|
||
unitInfo.UnitId = unit.Id;
|
||
unitInfo.ConfigId = unit.ConfigId;
|
||
unitInfo.Type = (int)unit.Type;
|
||
unitInfo.Position = unit.Position;
|
||
unitInfo.Forward = unit.Forward;
|
||
|
||
MoveComponent moveComponent = unit.GetComponent<MoveComponent>();
|
||
if (moveComponent != null)
|
||
{
|
||
if (!moveComponent.IsArrived())
|
||
{
|
||
unitInfo.MoveInfo = new MoveInfo();
|
||
unitInfo.MoveInfo.Points.Add(unit.Position);
|
||
for (int i = moveComponent.N; i < moveComponent.Targets.Count; ++i)
|
||
{
|
||
float3 pos = moveComponent.Targets[i];
|
||
unitInfo.MoveInfo.Points.Add(pos);
|
||
}
|
||
}
|
||
}
|
||
|
||
foreach ((int key, long value) in nc.NumericDic)
|
||
{
|
||
unitInfo.KV.Add(key, value);
|
||
}
|
||
|
||
return unitInfo;
|
||
}
|
||
|
||
// 获取看见unit的玩家,主要用于广播
|
||
public static Dictionary<long, AOIEntity> GetBeSeePlayers(this Unit self)
|
||
{
|
||
return self.GetComponent<AOIEntity>().GetBeSeePlayers();
|
||
}
|
||
}
|
||
} |