public void ExitServer() { if (isServer) { //NetworkServer.DisconnectAll(); ProjectWNetworkManager networkManager = GameObject.FindObjectOfType <ProjectWNetworkManager> (); networkManager.StopClient(); NetworkManager.Shutdown(); //networkManager.StopServer (); } else { GameObject.FindObjectOfType <ProjectWNetworkManager> ().StopClient(); } }
void Start() { if (PlayerPrefs.HasKey(PlayerPrefStrings.SAVED_IP_TO_CONNECT)) { serverIPInput.text = PlayerPrefs.GetString(PlayerPrefStrings.SAVED_IP_TO_CONNECT); } else { print("No player pref server found"); } SetScreenIndex(0); ResetCursor(); if ((networkManager = GameObject.FindObjectOfType <ProjectWNetworkManager> ())) { NetworkManager.Shutdown(); Destroy(networkManager.gameObject); } networkManager = GameObject.Instantiate(networkManagerPrefab).GetComponent <ProjectWNetworkManager> (); // Dropdown workaround refreshes mapDropdown.value = 1; gamemodeDropdown.value = 1; mapDropdown.value = 0; gamemodeDropdown.value = 0; }
void Start() { networkManager = GameObject.FindObjectOfType <ProjectWNetworkManager> (); startPositions = startPositionParent.GetComponentsInChildren <Transform>(); classPrefabs = classPrefabHolder.prefabs; // If we created the game ourselves if (networkManager.teamItems.Length > 0 && !useSettingsOverride) { int teamCount = networkManager.teamItems.Length; teams = networkManager.teamItems; // GameMode & options int gamemodeType = networkManager.gameModeSelect; // Game time // People may forget the time limit in their games if (networkManager.gamemodeOptions[0].optionName == "Time Limit (m)") { gameTime = networkManager.gamemodeOptions [0].value * 60; // Time is passed in minutes, we use seconds here } else { print("Using default time limit"); gameTime = timeLimit; // TODO should we just make this infinite? } switch (gamemodeType) { // README if you want to add a gamemode, you MUST update this method with the specific gamemode class case 0: gameMode = this.gameObject.AddComponent <GameMode_Deathmatch> (); GameMode_Deathmatch dm = (GameMode_Deathmatch)gameMode; dm.gameOptions = networkManager.gamemodeOptions; break; default: gameMode = null; break; } } else { if (!(gameMode = this.GetComponent <GameMode>())) { Debug.LogWarning("Unable to find a gamemode. This game will only end from timing out"); } gameTime = timeLimit; networkManager.gameObject.GetComponent <NetworkManagerHUD> ().gameObject.SetActive(true); } if (isServer) { for (int i = 0; i > teams.Length; i++) { teams[i].teamIndex = i; } int botCount = 0; foreach (Bot bot in networkManager.botItems) { Transform startPosition = GetStartPosition(); int classIndex = ((bot.botType == -1) ? Random.Range(0, classPrefabs.Length - 1) : bot.botType); //print (classIndex + " " + classPrefabs.Length); int teamIndex = bot.botTeam != -1 ? bot.botTeam : Random.Range(0, teams.Length); string spawnName = bot.botName == "" ? classPrefabs [classIndex].name + " " + (botCount + 1) : bot.botName; //print (startPosition.position + " " + startPosition.rotation); GameObject spawn = GameObject.Instantiate(classPrefabs[classIndex], startPosition.position, startPosition.rotation); spawn.SendMessage("setBot", botCount + 1); PlayerStats stats = spawn.GetComponent <PlayerStats>(); stats.teamIndex = teams.Length > 1 ? teamIndex : -1; stats.teamColor = teams[teams.Length > 1 ? teamIndex : 0].teamColor; stats.teamColorIndex = teams[teams.Length > 1 ? teamIndex : 0].teamColorIndex; stats.classIndex = classIndex; stats.playerName = spawnName; PlayerGUI newPG = spawn.GetComponent <PlayerGUI>(); newPG.desiredPlayerName = stats.playerName; newPG.desiredPlayerClass = stats.classIndex; newPG.desiredTeamIndex = stats.teamIndex; spawn.name = stats.playerName; NetworkServer.Spawn(spawn); botCount++; } } else { // this should not do anything, but should still display values such as time remaining and teams this.gameObject.SetActive(false); } }