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, Map map, long roomId) { 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) { self.allMaps.Remove(instanceId); } public static Map[] GetAll(this GameMapComponent self) { return self.allMaps.Values.ToArray(); } public static Map GetMapByRoomId(this GameMapComponent self, long roomId) { long instanceId = self.rooms[roomId]; if (instanceId > 0) { return self.Get(instanceId); } return null; } } }