/// <summary> /// Removes the player. /// </summary> /// <param name="connection">Connection.</param> public void RemovePlayer(Connection connection) { var connectInfos = ConnectionManager.Get(connection); var cos = connectInfos.Lobby.Connection.ToArray(); foreach (var lobbyConnection in cos) { //var connectInfos = ConnectionManager.Get(connection); var lobbyConnectInfos = ConnectionManager.Get(lobbyConnection); var pseudo = lobbyConnectInfos.Pseudo; if ((IsStarted == false && connection == lobbyConnection) || IsStarted) { Console.WriteLine("[LobbyRoom - " + _name + "] " + pseudo + " disconnected"); _connections.Remove(lobbyConnection); if (_connections.Count == 0) { LobbyManager.DeleteLobby(_name); } lobbyConnectInfos.Lobby = null; LobbyRoom.Unregister(lobbyConnection); NetworkGame.Unregister(lobbyConnection); if (lobbyConnection.ConnectionInfo.ConnectionState == ConnectionState.Established) { Console.WriteLine("Client: " + pseudo + " is still connected, register it on LobbySelector"); SelectLobby.Register(lobbyConnection); lobbyConnection.SendObject("LobbySelect"); } } } }
//处理房间内部信息 private void DealRoomData(string[] strs) { switch (strs[2]) { //处理粗略信息 case "1": RoomList = new ObservableCollection <LobbyRoom>(); for (int i = 0; i < (strs.Length - 3) / 4; i++) { LobbyRoom lr = new LobbyRoom(); lr.RNum = int.Parse(strs[4 * i + 3]); lr.Num = int.Parse(strs[4 * i + 4]); lr.Creater = strs[4 * i + 5]; lr.Status = strs[4 * i + 6]; RoomList.Add(lr); } break; //处理详细信息 case "2": PlayerList = new ObservableCollection <LobbyPlayer>(); for (int i = 0; i < (strs.Length - 4) / 3; i++) { LobbyPlayer lp = new LobbyPlayer(); lp.SNum = int.Parse(strs[3 * i + 4]); lp.Nick = strs[3 * i + 5]; lp.Exp = int.Parse(strs[3 * i + 6]); PlayerList.Add(lp); } break; } }
void CreateRoom() { RoomOptions roomOptions = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = 4 }; if (PhotonNetwork.CreateRoom(RoomName.text, roomOptions, TypedLobby.Default)) { print("Create room succed"); CurrentRoom.SetActive(true); LobbyRoom.SetActive(false); } else { print("Create room failed"); } }
public void OnEnable() { instance = this; }