Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Update() {
- // Are we the master client?
- _server = PhotonNetwork.isMasterClient;
- // Check if we need to swap levels for preview.
- if (previewSwapRequested) {
- // Check if the swap timer has waited 5 seconds, and the last preview loaded its level.
- if (previewSwapTimer.ElapsedMilliseconds >= 5000 && (levelLoadingCheck != null ? levelLoadingCheck.isDone : true)) {
- string levelName = null;
- // Set the respective map.
- if (gameType == GameType.CTF) {
- string[] ctfMaps = MapList.CTFMaps();
- if (ctfMaps.Length < mapsDropdown.value) {
- mapsDropdown.value = 0;
- }
- levelName = ctfMaps[mapsDropdown.value];
- }
- if (gameType == GameType.Territores) {
- string[] territoriesMap = MapList.TerritoriesMaps();
- if (territoriesMap.Length < mapsDropdown.value) {
- mapsDropdown.value = 0;
- }
- levelName = territoriesMap[mapsDropdown.value];
- }
- if (gameType == GameType.Elimination) {
- string[] eliminationMaps = MapList.EliminationMaps();
- if (eliminationMaps.Length < mapsDropdown.value) {
- mapsDropdown.value = 0;
- }
- levelName = eliminationMaps[mapsDropdown.value];
- }
- // Has this level been loaded before?
- if (lastLevelLoaded != levelName) {
- // Load the level.
- LoadLevel(levelName);
- // Set the skybox.
- rotator.GetComponent<Camera>().clearFlags = CameraClearFlags.Skybox;
- }
- // Reset everything.
- previewSwapRequested = false;
- hasSpawnedMainMenuLevel = true;
- previewSwapTimer.Reset();
- }
- }
- // Is this server manager a dummy?
- if (!isDud) {
- // Are we matchmaking, and the master client?
- if (isMatchMaking && PhotonNetwork.isMasterClient) {
- // Check if the matchmaking timer isn't running.
- if (!matchmakingTimer.IsRunning) {
- // If it isn't, we have to start it.
- matchmakingTimer.Start();
- }
- // Have we waited 10 seconds?
- if (matchmakingTimer.ElapsedMilliseconds >= 10000) {
- // If so, lets check to see if we have enough players to start a match.
- photonView.RPC("CheckPlayers", PhotonTargets.AllBufferedViaServer);
- }
- }
- // Check to see if we have enough players, and are matchmaking, or that this is a custom game and we can start the room.
- if ((PhotonNetwork.playerList.Length >= playersRequiredToStartMatch && isMatchMaking)
- || (isCustomGame && isReadyToStartGame && PhotonNetwork.connectedAndReady)) {
- if (isMatchMaking) {
- if (_server) {
- if (playersRequiredToStartMatch >= 4) {
- // PhotonNetwork.room.open = false;
- }
- }
- }
- // Make sure we're connected to a room
- if (PhotonNetwork.connectionStateDetailed == PeerState.Joined) {
- // Is this a custom game?
- if (isCustomGame) {
- // Are we the master server or offline?
- if (PhotonNetwork.isMasterClient || PhotonNetwork.offlineMode) {
- // Do we still have plans to load a level?
- if (!sentLevelLoadRequest) {
- if (!previewSwapTimer.IsRunning) {
- previewSwapTimer.Start();
- }
- // Check to see that we've waited 5 seconds, and that the last level finished loading.
- if (previewSwapTimer.ElapsedMilliseconds >= 5000 && levelLoadingCheck.isDone) {
- levelLoaded = false;
- string levelName = null;
- // Get the name of the respective map.
- if (gameType == GameType.CTF) {
- string[] ctfMaps = MapList.CTFMaps();
- if (ctfMaps.Length < mapsDropdown.value) {
- mapsDropdown.value = 0;
- }
- levelName = ctfMaps[mapsDropdown.value];
- }
- if (gameType == GameType.Territores) {
- string[] territoriesMap = MapList.TerritoriesMaps();
- if (territoriesMap.Length < mapsDropdown.value) {
- mapsDropdown.value = 0;
- }
- levelName = territoriesMap[mapsDropdown.value];
- }
- if (gameType == GameType.Elimination) {
- string[] eliminationMaps = MapList.EliminationMaps();
- if (eliminationMaps.Length < mapsDropdown.value) {
- mapsDropdown.value = 0;
- }
- levelName = eliminationMaps[mapsDropdown.value];
- }
- // Did we load this map aready?
- if (lastLevelLoaded != levelName) {
- // Load the map.
- photonView.RPC("LoadLevel", PhotonTargets.AllBufferedViaServer, levelName);
- }
- // We've loaded our map.
- sentLevelLoadRequest = true;
- }
- }
- }
- } else {
- // Are we the server?
- if (PhotonNetwork.isMasterClient || PhotonNetwork.offlineMode) {
- // Do we still have plans to load a level?
- if (!sentLevelLoadRequest) {
- levelLoaded = false;
- string levelName = "";
- // Get the respective level name.
- if (gameType == GameType.CTF) {
- string[] maps = MapList.CTFMaps();
- levelName = maps[Mathf.RoundToInt(UnityEngine.Random.Range(0f, (100f * (float)maps.Length)) / 100f)];
- }
- if (gameType == GameType.Territores) {
- string[] maps = MapList.TerritoriesMaps();
- levelName = maps[Mathf.RoundToInt(UnityEngine.Random.Range(0f, (100f * (float)maps.Length)) / 100f)];
- }
- if (gameType == GameType.Elimination) {
- string[] maps = MapList.EliminationMaps();
- levelName = maps[Mathf.RoundToInt(UnityEngine.Random.Range(0f, (100f * (float)maps.Length)) / 100f)];
- }
- // Has this map been loaded already?
- if (lastLevelLoaded != levelName) {
- // Load the map.
- photonView.RPC("LoadLevel", PhotonTargets.AllBufferedViaServer, levelName);
- }
- // We've loaded the map.
- sentLevelLoadRequest = true;
- }
- }
- }
- if (levelTimer == null) {
- levelTimer = new Stopwatch();
- }
- if (!levelLoaded) {
- levelTimer.Start();
- }
- // Have we loaded a map at all?
- if (levelLoadingCheck != null) {
- // Has the map finished loading?
- if (levelLoadingCheck.isDone) {
- // Disable the selection menu.
- DisableMenus();
- //UnityEngine.Debug.Log("Level Loaded.");
- levelLoaded = true;
- if (matchStarted != null) {
- matchStarted(this, EventArgs.Empty);
- }
- // Has the team manager figured out the team colours, or are we a client?
- if (teamManager.hasAssignedColors || !PhotonNetwork.isMasterClient) {
- levelTimer.Reset();
- // Have any players been created yet?
- if (!_playerCreated) {
- // Get the spawn points.
- Spawn[] spawns = FindObjectsOfType<Spawn>();
- _playerCount = 0;
- // Is there mouse and keyboard as an input, or no controllers plugged in?
- if (ControllerConfig.HasMouseKeyboardConfigured || ControllerConfig.NoControllers) {
- // Increment the player count.
- _playerCount++;
- }
- // Add however many controllers are connected to the player count.
- _playerCount += GamePadManager.GamePadCount;
- int currentSpawn = 0;
- // Spawn all the players.
- for (int i = 0; i < _playerCount; i++) {
- SpawnPlayer(spawns[currentSpawn++].transform.position);
- }
- // Are we the server, not matchmaking, and offline?
- if (PhotonNetwork.isMasterClient && !isMatchMaking && PhotonNetwork.offlineMode) {
- // How many players are there?
- int playerCount = FindObjectsOfType<PlayerController>().Length;
- // Spawn enough AI players to fill the max player limit.
- if (playerCount < maxPlayers) {
- for (int i = 0; i < maxPlayers - playerCount; i++) {
- botsSpawned++;
- SpawnAI(spawns[currentSpawn++].transform.position, i);
- }
- }
- }
- // Players are done being spawned.
- _playerCreated = true;
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment