Files
TEngine/Assets/GameScripts/DotNet/Hotfix/Server/Demo/Map/Unit/UnitHelper.cs
ALEXTANG 336d4b2eb9 [+] 接入ET8服务端
[+] 接入ET8服务端
2023-07-13 12:23:48 +08:00

49 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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();
}
}
}