UnitHelper.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections.Generic;
  2. namespace ET
  3. {
  4. public static class UnitHelper
  5. {
  6. public static UnitInfo CreateUnitInfo(Unit unit)
  7. {
  8. UnitInfo unitInfo = new UnitInfo();
  9. NumericComponent nc = unit.GetComponent<NumericComponent>();
  10. unitInfo.X = unit.Position.x;
  11. unitInfo.Y = unit.Position.y;
  12. unitInfo.Z = unit.Position.z;
  13. unitInfo.UnitId = unit.Id;
  14. unitInfo.ConfigId = unit.ConfigId;
  15. foreach ((int key, long value) in nc.NumericDic)
  16. {
  17. unitInfo.Ks.Add(key);
  18. unitInfo.Vs.Add(value);
  19. }
  20. return unitInfo;
  21. }
  22. // 获取看见unit的玩家,主要用于广播
  23. public static Dictionary<long, AOIEntity> GetBeSeePlayers(this Unit self)
  24. {
  25. return self.GetComponent<AOIEntity>().GetBeSeePlayers();
  26. }
  27. public static void NoticeUnitAdd(Unit unit, Unit sendUnit)
  28. {
  29. M2C_CreateUnits createUnits = new M2C_CreateUnits();
  30. createUnits.Units.Add(CreateUnitInfo(sendUnit));
  31. MessageHelper.SendToClient(unit, createUnits);
  32. }
  33. public static void NoticeUnitRemove(Unit unit, Unit sendUnit)
  34. {
  35. M2C_RemoveUnits removeUnits = new M2C_RemoveUnits();
  36. removeUnits.Units.Add(sendUnit.Id);
  37. MessageHelper.SendToClient(unit, removeUnits);
  38. }
  39. }
  40. }