GameMapComponentSystem.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Linq;
  2. namespace ET.Server
  3. {
  4. [FriendOf(typeof (GameMapComponent))]
  5. public static class GameMapComponentSystem
  6. {
  7. public class GameMapComponentAwakeSystem: AwakeSystem<GameMapComponent>
  8. {
  9. /// <summary>
  10. /// 游戏服场景组件创建
  11. /// </summary>
  12. /// <param name="self"></param>
  13. protected override void Awake(GameMapComponent self)
  14. {
  15. GameMapComponent.Instance = self;
  16. // todo 添加场景销毁检测定时器
  17. }
  18. }
  19. public class GameMapComponentDestroySystem: DestroySystem<GameMapComponent>
  20. {
  21. /// <summary>
  22. /// 游戏服场景组件销毁
  23. /// </summary>
  24. /// <param name="self"></param>
  25. protected override void Destroy(GameMapComponent self)
  26. {
  27. }
  28. }
  29. public static void Add(this GameMapComponent self, long roomId, Map map)
  30. {
  31. self.allMaps.TryAdd(map.Id, map);
  32. // 映射一下roomId与instanceId的关系
  33. self.rooms.TryAdd(roomId, map.Id);
  34. }
  35. public static Map Get(this GameMapComponent self, long instanceId)
  36. {
  37. self.allMaps.TryGetValue(instanceId, out Map map);
  38. return map;
  39. }
  40. public static void Remove(this GameMapComponent self, long instanceId)
  41. {
  42. self.allMaps.Remove(instanceId);
  43. }
  44. public static Map[] GetAll(this GameMapComponent self)
  45. {
  46. return self.allMaps.Values.ToArray();
  47. }
  48. public static Map GetMapByRoomId(this GameMapComponent self, long roomId)
  49. {
  50. long instanceId = self.rooms[roomId];
  51. if (instanceId > 0)
  52. {
  53. return self.Get(instanceId);
  54. }
  55. return null;
  56. }
  57. }
  58. }