// spawn each player pair at a respective spawnpoint // to do this, loop through each player in the gamestate tracker and get a list of the unique teams // once we have this, get the driver and gunner from both. // instantiate the driver's vehicle for each of them (driver character) // instantiate the gunner attached to the vehicle for each of them (gunner character) // only to be called by the master client when we can be sure that everyone has loaded into the game IEnumerator SpawnPlayers() { spawningPlayersScreenInstance = Instantiate(spawningPlayersScreenPrefab, transform.position, Quaternion.identity); // yield return new WaitForSecondsRealtime(0.5f); // if(FindObjectOfType<MakeTheMap>() != null) FindObjectOfType<MakeTheMap>().MakeMap(); yield return(new WaitForSecondsRealtime(1f)); if (PhotonNetwork.IsMasterClient) { GamestateTracker gamestateTracker = FindObjectOfType <GamestateTracker>(); // players should have already had their teams validated through the lobby screen // If we end up with bugs, get Jordan to add extra checks to fill slots with bots at this point. for (short i = 0; i < gamestateTracker.teams.count; i++) { TeamEntry entry = gamestateTracker.teams.GetAtIndex(i); int teamId = entry.id; entry.Release(); // instantiate the vehicle from the vehiclePrefabName in the schema, if null, instantiate the testing truck Spawn(teamId); yield return(new WaitForSeconds(0.5f)); } GameFullySetupMaster(); } }
public void SetupDriverAbilityManager() { isHost = PhotonNetwork.IsMasterClient; ultimateUiManager = FindObjectOfType <UltimateUiManager>(); gamestateTracker = FindObjectOfType <GamestateTracker>(); driverPhotonView = GetComponent <PhotonView>(); NetworkPlayerVehicle npv = GetComponent <NetworkPlayerVehicle>(); if (npv != null) { driverId = npv.GetDriverID(); if (driverId == PhotonNetwork.LocalPlayer.ActorNumber) { isDriver = true; } gunnerId = npv.GetGunnerID(); if (driverId < 0) { driverBot = true; } if (gunnerId < 0) { gunnerBot = true; } AdjustDriverUltimateProgress(0); } abilityPrimary.SetupAbility(); abilitySecondary.SetupAbility(); gunnerWeaponManager = GetComponentInChildren <GunnerWeaponManager>(); isSetup = true; // abilitySecondary.SetupAbility(); }
public virtual void SetupHealthManager() { gamestateTracker = FindObjectOfType <GamestateTracker>(); gamestateTrackerPhotonView = gamestateTracker.GetComponent <PhotonView>(); networkManager = FindObjectOfType <NetworkManager>(); maxHealth = health; myPhotonView = GetComponent <PhotonView>(); }
void Start() { _gamestateTracker = FindObjectOfType <GamestateTracker>(); if (uninteractableIfNotMaster && !PhotonNetwork.IsMasterClient) { GetComponent <Button>().interactable = false; } }
public void CheckState() { stateTracker = GameObject.FindGameObjectWithTag("Player").GetComponent <GamestateTracker>(); if (stateTracker != null) { stateTracker.Updatestep(); } }
public void StartGame() { GamestateTracker gamestateTracker = FindObjectOfType <GamestateTracker>(); //SynchroniseSchemaBeforeSpawn(); // change back StartCoroutine(SpawnPlayers()); }
// Start is called before the first frame update void Start() { if (lobbySlotMaster == null) { lobbySlotMaster = FindObjectOfType <LobbySlotMaster>(); } gamestateTracker = FindObjectOfType <GamestateTracker>(); }
// Start is called before the first frame update void Start() { GamestateTracker gst = GameObject.FindGameObjectWithTag("Player").GetComponent <GamestateTracker>(); if (gst.Gamestep == 5) { GetComponent <BoxCollider2D>().enabled = false; } }
// Start is called before the first frame update void Start() { #if UNITY_WEBGL && !UNITY_EDITOR unmute(); // Allow players to speak to everyone again in the VC. #endif gamestateTracker = FindObjectOfType <GamestateTracker>(); UpdateText(); Cursor.lockState = CursorLockMode.None; }
// Start is called before the first frame update void Start() { // Debug.LogWarning("Car Checkpoints has not been ported to the new PhysX system"); // return; gamestateTracker = FindObjectOfType <GamestateTracker>(); bc = (BasicCheckpoint)FindObjectOfType(typeof(BasicCheckpoint)); if (!bc) { Debug.LogWarning("No BasicCheckpoint object could be found (this is fine in menus but BAD in game"); } }
void Start() { gamestateTracker = FindObjectOfType <GamestateTracker>(); gamestateVehicleLookup = FindObjectOfType <GamestateVehicleLookup>(); vehicleNames = gamestateVehicleLookup.sortedVehicleNames; PlayerEntry playerEntry = gamestateTracker.players.Get((short)PhotonNetwork.LocalPlayer.ActorNumber); PlayerEntry.Role ourRole = (PlayerEntry.Role)playerEntry.role; ourTeamId = playerEntry.teamId; playerEntry.Release(); // get the team we are in TeamEntry teamEntry = gamestateTracker.teams.Get(ourTeamId); short driverId = teamEntry.driverId; short gunnerId = teamEntry.gunnerId; teamEntry.Release(); // if we are a gunner, check if the driver is a bot. // if so, get priority if (ourRole == PlayerEntry.Role.Gunner) { PlayerEntry driverEntry = gamestateTracker.players.Get(driverId); if (driverEntry.isBot) { priority = true; } driverEntry.Release(); } // if we are a driver, get priority if (ourRole == PlayerEntry.Role.Driver) { priority = true; } // assign other player id, only needed if the other player is human // hence we only check for if we are a driver if (priority && ourRole == PlayerEntry.Role.Driver) { // get gunner id PlayerEntry gunnerEntry = gamestateTracker.players.Get(gunnerId); otherId = gunnerEntry.id; gunnerEntry.Release(); } SetButtonsInteractable(priority); SetupButtons(); }
void TransferDriverPhotonViewOwnership() { // lookup the player from the gamestate tracker if (PhotonNetwork.IsMasterClient) { gamestateTracker = FindObjectOfType <GamestateTracker>(); // gamestateTracker.ForceSynchronisePlayerList(); Player p = PhotonNetwork.CurrentRoom.GetPlayer(driverId); //Debug.Log("Player p in driver transfer: " + p.ToString() + " name: " + p.NickName); //Debug.Log("driver in transfer: " + p.NickName); driverPhotonView.TransferOwnership(p); } }
void Spawn(int teamId) { GamestateTracker gamestateTracker = FindObjectOfType <GamestateTracker>(); TeamEntry teamEntry = gamestateTracker.teams.Get((short)teamId); bool selected = teamEntry.hasSelectedVehicle; teamEntry.isDead = false; short vehicle = teamEntry.vehicle; teamEntry.Commit(RespawnErrorHandler); Transform sp; if (teamId > spawnPoints.Count) { sp = spawnPoints[0]; } else { sp = spawnPoints[teamId - 1]; } List <string> vehicleNames = gamestateTracker.GetComponent <GamestateVehicleLookup>().sortedVehicleNames; string vehiclePrefabName; if (selected) { vehiclePrefabName = "VehiclePrefabs/" + vehicleNames[vehicle]; } else { int randomVehicleNumber = Random.Range(0, defaultPlayerVehiclePrefabNames.Count); vehiclePrefabName = defaultPlayerVehiclePrefabNames[randomVehicleNumber]; TeamEntry teamEntryAgain = gamestateTracker.teams.Get((short)teamId); teamEntryAgain.vehicle = (short)randomVehicleNumber; teamEntryAgain.hasSelectedVehicle = true; teamEntryAgain.Commit(); } object[] instantiationData = new object[] { teamId }; //Put strong brakes on for spawn var spawnedVehicle = PhotonNetwork.Instantiate(vehiclePrefabName, sp.position, sp.rotation, 0, instantiationData); /* * PhysXWheelCollider[] wheelColliders = spawnedVehicle.GetComponentsInChildren<PhysXWheelCollider>(); * foreach (PhysXWheelCollider wc in wheelColliders) { * wc.brakeTorque = 10000; * }*/ }
// Start is called before the first frame update void Start() { if (lockCursorToWindow && FindObjectOfType <PlinthManager>() == null) { Cursor.lockState = CursorLockMode.Locked; } gamestateTracker = FindObjectOfType <GamestateTracker>(); cam = GetComponentInChildren <CinemachineFreeLook>(); firstPersonCam = GetComponentInChildren <CinemachineVirtualCamera>(); firstPersonCam.enabled = false; vehicleManager = GetComponentInParent <VehicleHealthManager>(); thirdPersonFocus = cam.LookAt; // Give the vehicle manager time to assign teamIds //Invoke(nameof(AssignPriority), 3f); AssignPriority(); }
public void CacheRole() { if (!cachedRole) { GamestateTracker gs = FindObjectOfType <GamestateTracker>(); PlayerEntry playerEntry = gs.players.Read((short)PhotonNetwork.LocalPlayer.ActorNumber); if (playerEntry.role == (short)PlayerEntry.Role.Driver) { isDriver = true; } if (playerEntry.role == (short)PlayerEntry.Role.Gunner) { isGunner = true; } } }
// called by the lobby button master when we create a team public void CreateTeamEntry() { lobbySlotMaster = FindObjectOfType <LobbySlotMaster>(); gamestateTracker = FindObjectOfType <GamestateTracker>(); // new gamestate tracker register team TeamEntry teamEntry = gamestateTracker.teams.Create(true, false); // add a listener to team record // TeamEntry teamEntry = gamestateTracker.teams.Get((short)teamId); teamEntry.Commit(); GetComponent <PhotonView>().RPC(nameof(AddListenerToThisTeam), RpcTarget.AllBufferedViaServer); }
// Start is called before the first frame update void Start() { gamestateTracker = FindObjectOfType <GamestateTracker>(); PlayerEntry player = gamestateTracker.players.Get((short)PhotonNetwork.LocalPlayer.ActorNumber); if (player.role == (short)PlayerEntry.Role.Driver) { tutorials[0] = true; Invoke(nameof(ActivateDriftObject), 30f); } if (player.role == (short)PlayerEntry.Role.Gunner) { tutorials[1] = true; } player.Release(); }
// Return the teams from the gamestate tracker, sorted by score. public List <TeamEntry> SortTeams(GamestateTracker gamestateTracker) { List <TeamEntry> unsortedTeams = new List <TeamEntry>(); for (int i = 0; i < gamestateTracker.teams.count; i++) { TeamEntry team = gamestateTracker.teams.GetAtIndex(i); unsortedTeams.Add(team); team.Release(); } List <TeamEntry> sortedTeams = unsortedTeams; sortedTeams.Sort((t1, t2) => CalcScore(t1).CompareTo(CalcScore(t2))); sortedTeams.Reverse(); return(sortedTeams); }
void TransferGunnerPhotonViewOwnership() { // lookup the player from the gamestate tracker if (PhotonNetwork.IsMasterClient) { gamestateTracker = FindObjectOfType <GamestateTracker>(); // gamestateTracker.ForceSynchronisePlayerList(); Player p = PhotonNetwork.CurrentRoom.GetPlayer(gunnerId); //Debug.Log("gunner nickname in transfer: " + p.NickName); gunnerPhotonView.TransferOwnership(p); Weapon[] weapons = GetComponentsInChildren <Weapon>(); foreach (Weapon weapon in weapons) { weapon.gameObject.GetComponent <PhotonView>().TransferOwnership(p); } } }
// Start is called before the first frame update void Start() { gamestateTracker = FindObjectOfType <GamestateTracker>(); gamestateVehicleLookup = FindObjectOfType <GamestateVehicleLookup>(); dropdown = GetComponent <Dropdown>(); dropdown.ClearOptions(); vehicleNames = gamestateVehicleLookup.sortedVehicleNames; List <Dropdown.OptionData> options = new List <Dropdown.OptionData>(); for (int i = 0; i < vehicleNames.Count; i++) { options.Add(new Dropdown.OptionData(vehicleNames[i])); } dropdown.AddOptions(options); selectedVehicle = vehicleNames[0]; }
void Start() { playersInRoom = PhotonNetwork.CurrentRoom.PlayerCount; // get the next scene from the gamestate tracker tracker = FindObjectOfType <GamestateTracker>(); nextScene = tracker.nextMap; nextSceneDisplayName = tracker.nextMapDisplay; nextMapText.text = nextSceneDisplayName; // tell all players to load it async playersInLobby = PhotonNetwork.CurrentRoom.PlayerCount; if (PhotonNetwork.IsMasterClient) { GetComponent <PhotonView>().RPC(nameof(StartLoadAsync_RPC), RpcTarget.All); } // when done, callback to the master, buffered via server // when number of finished players = players in room, then load the next scene }
// Enable the arrow and find the player's own vehicle. Shouldn't be called until all vehicles are activated. public void ReadyUp() { hpms = FindObjectsOfType <HotPotatoManager>().ToList(); gamestateTracker = FindObjectOfType <GamestateTracker>(); meshRenderer = GetComponentInChildren <MeshRenderer>(); PlayerEntry player = gamestateTracker.players.Get((short)PhotonNetwork.LocalPlayer.ActorNumber); List <NetworkPlayerVehicle> vehicles = FindObjectsOfType <NetworkPlayerVehicle>().ToList(); foreach (NetworkPlayerVehicle vehicle in vehicles) { if (vehicle.teamId == player.teamId) { playerNPV = vehicle; playerHPM = vehicle.GetComponent <HotPotatoManager>(); player.Release(); break; } } isEnabled = true; }
void ActivateVehicles() { NetworkPlayerVehicle[] npvs = FindObjectsOfType <NetworkPlayerVehicle>(); foreach (NetworkPlayerVehicle npv in npvs) { npv.GetComponent <PhotonView>().RPC(nameof(NetworkPlayerVehicle.ActivateVehicleInputs), RpcTarget.AllBufferedViaServer); } photonView.RPC(nameof(ActivateArrow_RPC), RpcTarget.All); physXSceneManager.doPhysics = true; GamestateTracker gamestateTracker = FindObjectOfType <GamestateTracker>(); GlobalsEntry globals = gamestateTracker.globals; float time = globals.timeLimit; globals.Release(); timer = FindObjectOfType <TimerBehaviour>(); if (timer != null) { timer.HostStartTimer(time); } }
private void Start() { gamestateTracker = FindObjectOfType <GamestateTracker>(); telecastManager = FindObjectOfType <TelecastManager>(); }
void Start() { gamestateTracker = GetComponent <GamestateTracker>(); }
// called by the lobby button master when we create a team public bool TeamRemoveEntry() { lobbySlotMaster = FindObjectOfType <LobbySlotMaster>(); gamestateTracker = FindObjectOfType <GamestateTracker>(); TeamEntry teamEntry = gamestateTracker.teams.Get((short)teamId); bool canRemove = true; // look for the corresponding players in the team // get driver player (if they exist) short driverId = teamEntry.driverId; if (driverId != 0) { PlayerEntry driverEntry = gamestateTracker.players.Get((short)driverId); // if they are bots, then kick them if (driverEntry.isBot) { driverEntry.Delete(); } // unready and unselect them else { canRemove = false; driverEntry.Release(); } } // get gunner player (if they exist) short gunnerId = teamEntry.gunnerId; if (gunnerId != 0) { PlayerEntry gunnerEntry = gamestateTracker.players.Get((short)gunnerId); if (gunnerEntry.isBot) { gunnerEntry.Delete(); } // unready and unselect them else { canRemove = false; gunnerEntry.Release(); } } if (canRemove) { Debug.Log("Deleting team entry"); teamEntry.Delete(); } else { teamEntry.Release(); } return(canRemove); }
// Called once the network manager deems it ready to display the scores. public void StartScoreboard() { gamestateTracker = FindObjectOfType <GamestateTracker>(); SetUpScoreboard(); }
void IPunInstantiateMagicCallback.OnPhotonInstantiate(PhotonMessageInfo info) { Debug.Log("Spawn start"); GetComponent <VehicleHealthManager>().SetupVehicleManager(); gamestateTracker = FindObjectOfType <GamestateTracker>(); teamId = (int)info.photonView.InstantiationData[0]; gameObject.name = gameObject.name + teamId; MonoBehaviour[] scripts = GetComponentsInChildren <MonoBehaviour>(true); List <MonoBehaviour> playerDriverScriptsList = new List <MonoBehaviour>(); List <MonoBehaviour> playerGunnerScriptsList = new List <MonoBehaviour>(); List <MonoBehaviour> aiDriverScriptsList = new List <MonoBehaviour>(); List <MonoBehaviour> aiGunnerScriptsList = new List <MonoBehaviour>(); foreach (MonoBehaviour script in scripts) { object[] vehicleScriptAttributes = script.GetType().GetCustomAttributes(typeof(VehicleScript), false); foreach (object attribute in vehicleScriptAttributes) { VehicleScript vehicleScript = attribute as VehicleScript; if (vehicleScript == null) { Debug.LogWarning("Non-VehicleScript script picked up"); } else { if (vehicleScript.scriptType == ScriptType.playerDriverScript) { playerDriverScriptsList.Add(script); } if (vehicleScript.scriptType == ScriptType.playerGunnerScript) { playerGunnerScriptsList.Add(script); } if (vehicleScript.scriptType == ScriptType.aiDriverScript) { aiDriverScriptsList.Add(script); } if (vehicleScript.scriptType == ScriptType.aiGunnerScript) { aiGunnerScriptsList.Add(script); } } } } playerDriverScripts = playerDriverScriptsList.ToArray(); playerGunnerScripts = playerGunnerScriptsList.ToArray(); aiDriverScripts = aiDriverScriptsList.ToArray(); aiGunnerScripts = aiGunnerScriptsList.ToArray(); //GamestateTracker.PlayerDetails driverDetails = gamestateTracker.GetPlayerWithDetails(role: "Driver", teamId: teamId); //GamestateTracker.PlayerDetails gunnerDetails = gamestateTracker.GetPlayerWithDetails(role: "Gunner", teamId: teamId); PlayerEntry driverEntry = gamestateTracker.players.Find((PlayerEntry entry) => { return(entry.role == (short)PlayerEntry.Role.Driver && entry.teamId == teamId); }); driverNickName = driverEntry.name; driverId = driverEntry.id; botDriver = driverEntry.isBot; PlayerEntry gunnerEntry = gamestateTracker.players.Find((PlayerEntry entry) => { return(entry.role == (short)PlayerEntry.Role.Gunner && entry.teamId == teamId); }); gunnerNickName = gunnerEntry.name; gunnerId = gunnerEntry.id; botGunner = gunnerEntry.isBot; GetComponentInChildren <PotatoEffects>().Setup(); // firstly, if the gunner is a human, transfer the photonview ownership to the player's client PhotonNetwork.AddCallbackTarget(GetComponentInChildren <GunnerWeaponManager>()); if (!botDriver) { TransferDriverPhotonViewOwnership(); } if (!botGunner) { TransferGunnerPhotonViewOwnership(); } // transfer control to master client if bot if (botDriver) { driverPhotonView.TransferOwnership(PhotonNetwork.MasterClient); } if (botGunner) { gunnerPhotonView.TransferOwnership(PhotonNetwork.MasterClient); } }
// Start is called before the first frame update void Start() { gamestateTracker = FindObjectOfType <GamestateTracker>(); timeLeft = timeToDestruct; timeLeftText.text = timeLeft.ToString(); }
private void Start() { gamestate = GameObject.FindGameObjectWithTag("Player").GetComponent <GamestateTracker>(); }