public static void Update(this MatchComponent self) { while (true) { MatcherComponent matcherComponent = Game.Scene.GetComponent <MatcherComponent>(); Queue <Matcher> matchers = new Queue <Matcher>(matcherComponent.GetAll()); MatchRoomComponent roomManager = Game.Scene.GetComponent <MatchRoomComponent>(); Room room = roomManager.GetReadyRoom(); if (matchers.Count == 0) { //当没有匹配玩家时直接结束 break; } if (room == null && matchers.Count >= 3) { //当还有一桌匹配玩家且没有可加入房间时使用空房间 room = roomManager.GetIdleRoom(); } if (room != null) { //当有准备状态房间且房间还有空位时匹配玩家直接加入填补空位 while (matchers.Count > 0 && room.Count < 3) { self.JoinRoom(room, matcherComponent.Remove(matchers.Dequeue().UserID)); } } else if (matchers.Count >= 3) { //当还有一桌匹配玩家且没有空房间时创建新房间 self.CreateRoom(); break; } else { break; } //移除匹配成功玩家 while (self.MatchSuccessQueue.Count > 0) { matcherComponent.Remove(self.MatchSuccessQueue.Dequeue().UserID); } } }