void Start() { DontDestroyOnLoad(gameObject); var ugly = UnityThreadHelper.Dispatcher; // If clients will be looking at localhost anyway, don't // pollute the network with broadcasts if (!Flags.GAME_SERVER_IS_LOCALHOST) { transform.gameObject.AddComponent <DiscoveryServer> (); } _networkLobbyManager = transform.gameObject.AddComponent <GameLobbyManager> (); _meshDiscoveryServer = new MeshDiscoveryServer(); _meshTransferManager = new MeshTransferManager(); _networkLobbyManager.logLevel = UnityEngine.Networking.LogFilter.FilterLevel.Info; _networkLobbyManager.showLobbyGUI = false; _networkLobbyManager.minPlayers = MIN_REQ_PLAYERS; // seemingly weird neccesary hack. todo: add this to our compat implementation _networkLobbyManager.maxPlayers = MAX_DEVICES; _networkLobbyManager.maxConnections = MAX_DEVICES; _networkLobbyManager.lobbySlots = new NetworkLobbyPlayer[_networkLobbyManager.maxPlayers]; List <string> lobbyScenes = new List <string> (); lobbyScenes.Add("Idle"); lobbyScenes.Add("Leaderboard"); _networkLobbyManager.lobbyScenes = lobbyScenes; _networkLobbyManager.playScene = "Game"; _networkLobbyManager.lobbyPlayerPrefab = LobbyPlayerPrefab; _networkLobbyManager.gamePlayerPrefab = GamePlayerPrefab; _networkLobbyManager.networkPort = NetworkConstants.GAME_PORT; _networkLobbyManager.serverBindToIP = true; _networkLobbyManager.serverBindAddress = Network.player.ipAddress; Debug.Log(string.Format("bound to {0}", _networkLobbyManager.serverBindAddress)); _networkLobbyManager.customConfig = true; var config = _networkLobbyManager.connectionConfig; config.NetworkDropThreshold = 80; config.ConnectTimeout = 10000; config.DisconnectTimeout = 10000; config.PingTimeout = 2000; _networkLobbyManager.channels.Add(UnityEngine.Networking.QosType.ReliableFragmented); _networkLobbyManager.channels.Add(UnityEngine.Networking.QosType.ReliableFragmented); _networkLobbyManager.StartServer(); // register listeners for when players connect / disconnect _networkLobbyManager.OnLobbyServerConnectedEvent += OnGamePlayerConnected; _networkLobbyManager.OnLobbyServerDisconnectedEvent += OnGamePlayerDisconnected; _networkLobbyManager.OnLobbyClientReadyToBeginEvent += OnGamePlayerReady; _networkLobbyManager.OnLobbyClientGameLoadedEvent += OnPlayerGameLoaded; _meshDiscoveryServer.MeshServerDiscoveredEvent += OnMeshServerFound; _meshTransferManager.OnMeshDataReceivedEvent += OnMeshDataReceived; OnServerRequestLoadNewMesh(); if (StartMuted) { AudioListener.volume = 0.0f; } }