123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System.Linq;
- namespace ET.Server
- {
- [FriendOf(typeof (GameMapComponent))]
- public static class GameMapComponentSystem
- {
- public class GameMapComponentAwakeSystem: AwakeSystem<GameMapComponent>
- {
- /// <summary>
- /// 游戏服场景组件创建
- /// </summary>
- /// <param name="self"></param>
- protected override void Awake(GameMapComponent self)
- {
- GameMapComponent.Instance = self;
- // todo 添加场景销毁检测定时器
- }
- }
- public class GameMapComponentDestroySystem: DestroySystem<GameMapComponent>
- {
- /// <summary>
- /// 游戏服场景组件销毁
- /// </summary>
- /// <param name="self"></param>
- protected override void Destroy(GameMapComponent self)
- {
- }
- }
- public static void Add(this GameMapComponent self, long roomId, Map map)
- {
- self.allMaps.TryAdd(map.Id, map);
- // 映射一下roomId与instanceId的关系
- self.rooms.TryAdd(roomId, map.Id);
- }
- public static Map Get(this GameMapComponent self, long instanceId)
- {
- self.allMaps.TryGetValue(instanceId, out Map map);
- return map;
- }
- public static void Remove(this GameMapComponent self, long instanceId, long roomId)
- {
- self.allMaps.Remove(instanceId);
- // 移除一下roomId与instanceId的关系
- self.rooms.Remove(roomId);
- }
- public static Map[] GetAll(this GameMapComponent self)
- {
- return self.allMaps.Values.ToArray();
- }
- public static Map GetMapByRoomId(this GameMapComponent self, long roomId)
- {
- if (!self.rooms.TryGetValue(roomId, out long instanceId))
- {
- return null;
- }
- if (instanceId > 0)
- {
- return self.Get(instanceId);
- }
- return null;
- }
- }
- }
|