public void CreateRoom(RoomButton b) { if (isMultiplayer.value) { if (!isConnected.value) { // Cannot connect to server but tried to acces multiplayer } else { RoomOptions roomOptions = new RoomOptions(); roomOptions.MaxPlayers = 4; ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable { { "scene", b.scene } }; roomOptions.CustomRoomPropertiesForLobby = new string[] { "scene" }; roomOptions.CustomRoomProperties = properties; PhotonNetwork.CreateRoom(null, roomOptions, TypedLobby.Default); } } else { //This will be single player Room r = ScriptableObject.CreateInstance <Room>(); r.sceneName = b.scene; GameManagers.GetResourcesManager().currentRoom.Set(r); } }
//This function not be neccessary thanks to PUN2 public void AddMatches(List <RoomInfo> rooms) { SetDirtyRooms(); foreach (RoomInfo room in rooms) { //RoomButton createdRoom = GetRoomFromDict(room.Name); //Debug.Log(createdRoom); if (room.RemovedFromList == false) { RoomButton createdRoom = GetRoomFromDict(room.Name); if (createdRoom == null) { Debug.Log("New match found"); AddMatch(room); } else { Debug.Log("Match is still there"); createdRoom.isValid = true; } } } ClearNonValidRooms(); }
//This function may not be neccessary thanks to PUN2 private RoomButton GetRoomFromDict(string id) { RoomButton result = null; roomsDict.TryGetValue(id, out result); return(result); }
public void AddMatch(RoomInfo roomInfo) { GameObject go = Instantiate(matchPrefab); go.transform.SetParent(matchesParent); MatchSpawnPosition p = GetSpawnPos(); p.isUsed = true; go.transform.position = p.pos.position; go.transform.localScale = Vector3.one; RoomButton roomButton = go.GetComponent <RoomButton>(); roomButton.roomInfo = roomInfo; roomButton.isRoomCreated = true; roomButton.isValid = true; roomButton.room = ScriptableObject.CreateInstance <Room>(); object sceneObj = null; roomInfo.CustomProperties.TryGetValue("scene", out sceneObj); string sceneName = (string)sceneObj; roomButton.room.sceneName = sceneName; roomButton.room.roomName = roomInfo.Name; roomsDict.Add(roomInfo.Name, roomButton); }
public void SetRoom(RoomButton b) { if (b.isRoomCreated) { Set(b.room); MultiplayerLauncher.singleton.JoinRoom(b.roomInfo); } else { MultiplayerLauncher.singleton.CreateRoom(b); } }
public void SetRoomButton(RoomButton b) { roomButtonVariable.value = b; }