using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using ClientState = ExitGames.Client.Photon.LoadBalancing.ClientState; using RoomInfo = ExitGames.Client.Photon.LoadBalancing.RoomInfo; using RoomOptions = ExitGames.Client.Photon.LoadBalancing.RoomOptions; public class ButtonCreateLobby : ButtonOnClick { public override void OnClick() { if (GameTransition.Instance.state == GameState.Multiplayer){ GameTransition.Instance.state = GameState.ConnectionInProgress; Debug.Log("Creating room"); var ro = new RoomOptions(); ro.EmptyRoomTtl = 1000; ro.CleanupCacheOnLeave = true; ro.PlayerTtl = 500; ro.PublishUserId = false; ro.MaxPlayers = 2; // TODO: Expose this better string roomCode = string.Empty; var roomList = NetworkManager.net.RoomInfoList.Keys.ToList(); do { roomCode = string.Format("{0}{1}{2}{3}", RandomDigit(), RandomDigit(), RandomDigit(), RandomDigit()); } while (roomList.Contains(roomCode)); var success = NetworkManager.net.OpCreateRoomWithProperties(roomCode, ro, ExitGames.Client.Photon.LoadBalancing.TypedLobby.Default); if (success) { Debug.Log("Room created"); } else { Debug.Log("Failed to connect to room"); } } } private int RandomDigit() { return Random.Range(0, 10); } }