JoinOrCreateRoom
How do I use Join Or Create Room
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
1602 | public static bool JoinOrCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby) | 1 |
File name: PhotonNetwork.cs
Copy
1602 public static bool JoinOrCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby)
1603 {
1604 if (offlineMode)
1605 {
1606 if (offlineModeRoom != null)
1607 {
1608 Debug.LogError("JoinOrCreateRoom failed. In offline mode you still have to leave a room to enter another.");
1609 return false;
1610 }
1611
1612 offlineModeRoom = new Room(roomName, roomOptions);
1613 NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom); // in offline mode you create, too for JoinOrCreateRoom
1614 NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom);
1615 return true;
1616 }
1617
1618
1619 if (networkingPeer.server != ServerConnection.MasterServer || !connectedAndReady)
1620 {
1621 Debug.LogError("JoinOrCreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
1622 return false;
1623 }
1624
1625 if (string.IsNullOrEmpty(roomName))
1626 {
1627 Debug.LogError("JoinOrCreateRoom failed. A roomname is required. If you don't know one, how will you join?");
1628 return false;
1629 }
1630
1631 return networkingPeer.OpJoinRoom(roomName, roomOptions, typedLobby, true);
1632 }
JoinOrCreateRoom 118 lượt xem
Gõ tìm kiếm nhanh...