UnitHelper.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace ET.Server
  4. {
  5. [FriendOf(typeof(MoveComponent))]
  6. [FriendOf(typeof(NumericComponent))]
  7. public static class UnitHelper
  8. {
  9. public static UnitInfo CreateUnitInfo(Unit unit)
  10. {
  11. UnitInfo unitInfo = new UnitInfo();
  12. NumericComponent nc = unit.GetComponent<NumericComponent>();
  13. unitInfo.UnitId = unit.Id;
  14. unitInfo.ConfigId = unit.ConfigId;
  15. unitInfo.Type = (int)unit.Type;
  16. Vector3 position = unit.Position;
  17. unitInfo.X = position.x;
  18. unitInfo.Y = position.y;
  19. unitInfo.Z = position.z;
  20. Vector3 forward = unit.Forward;
  21. unitInfo.ForwardX = forward.x;
  22. unitInfo.ForwardY = forward.y;
  23. unitInfo.ForwardZ = forward.z;
  24. MoveComponent moveComponent = unit.GetComponent<MoveComponent>();
  25. if (moveComponent != null)
  26. {
  27. if (!moveComponent.IsArrived())
  28. {
  29. unitInfo.MoveInfo = new MoveInfo();
  30. for (int i = moveComponent.N; i < moveComponent.Targets.Count; ++i)
  31. {
  32. Vector3 pos = moveComponent.Targets[i];
  33. unitInfo.MoveInfo.X.Add(pos.x);
  34. unitInfo.MoveInfo.Y.Add(pos.y);
  35. unitInfo.MoveInfo.Z.Add(pos.z);
  36. }
  37. }
  38. }
  39. foreach ((int key, long value) in nc.NumericDic)
  40. {
  41. unitInfo.Ks.Add(key);
  42. unitInfo.Vs.Add(value);
  43. }
  44. return unitInfo;
  45. }
  46. // 获取看见unit的玩家,主要用于广播
  47. public static Dictionary<long, AOIEntity> GetBeSeePlayers(this Unit self)
  48. {
  49. return self.GetComponent<AOIEntity>().GetBeSeePlayers();
  50. }
  51. }
  52. }