diff --git a/Assets/Prefabs/Game/PauseMenu.prefab b/Assets/Prefabs/Game/PauseMenu.prefab index 810c2f4..6bc9ea4 100644 --- a/Assets/Prefabs/Game/PauseMenu.prefab +++ b/Assets/Prefabs/Game/PauseMenu.prefab @@ -2091,6 +2091,8 @@ GameObject: m_Component: - component: {fileID: 6431751770358054813} - component: {fileID: 1008376151640199170} + - component: {fileID: 7402969457012247330} + - component: {fileID: 4573322176111875793} m_Layer: 0 m_Name: PauseMenu m_TagString: PauseMenu @@ -2132,6 +2134,37 @@ MonoBehaviour: ControlsHeader: {fileID: 785062696961171354} ControlsButtonText: {fileID: 4533798804063372460} ControlsText: {fileID: 8276015047527584947} + runnerPrefab: {fileID: 3669633515805984294, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3} +--- !u!114 &7402969457012247330 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4414581513358013603} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 66519fc5420181e45850c591aa1179ec, type: 3} + m_Name: + m_EditorClassIdentifier: + allItems: [] +--- !u!114 &4573322176111875793 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4414581513358013603} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} + m_Name: + m_EditorClassIdentifier: + NetworkInstanceId: 0 + PrefabHash: 14656023668747719728 + PrefabHashGenerator: PauseMenu + AlwaysReplicateAsRoot: 0 + DontDestroyWithOwner: 0 --- !u!1 &4446168051527838164 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Preloader.unity b/Assets/Scenes/Preloader.unity index 7381ed6..4d3f0a7 100644 --- a/Assets/Scenes/Preloader.unity +++ b/Assets/Scenes/Preloader.unity @@ -312,6 +312,8 @@ MonoBehaviour: PlayerPrefab: 0 - Prefab: {fileID: 1439663680877494070, guid: 26d94b328352d534eaa6ece69b3d2cad, type: 3} PlayerPrefab: 0 + - Prefab: {fileID: 4414581513358013603, guid: 058744b4c7122c346bf39d014bb74ebd, type: 3} + PlayerPrefab: 0 PlayerPrefabHash: id: 0 CreatePlayerPrefab: 0 diff --git a/Assets/Scripts/Environment/ResetZonesGlobal.cs b/Assets/Scripts/Environment/ResetZonesGlobal.cs index bacc140..2d12eb1 100644 --- a/Assets/Scripts/Environment/ResetZonesGlobal.cs +++ b/Assets/Scripts/Environment/ResetZonesGlobal.cs @@ -33,7 +33,9 @@ public class ResetZonesGlobal : MonoBehaviour { foreach (GameObject character in playableCharacters) { if (character.GetComponent().OwnerClientId == clientID) { // Set their zone - character.GetComponent().SetCurrentZone(RespawnZone); + if (character.GetComponent() != null) { + character.GetComponent().SetCurrentZone(RespawnZone); + } } } } diff --git a/Assets/Scripts/PlayerScripts/ResetZones.cs b/Assets/Scripts/PlayerScripts/ResetZones.cs index 4a2bd26..2686750 100644 --- a/Assets/Scripts/PlayerScripts/ResetZones.cs +++ b/Assets/Scripts/PlayerScripts/ResetZones.cs @@ -14,10 +14,6 @@ public class ResetZones : MonoBehaviour { private Transform FoothillsRespawnPoint; private Transform MountainRespawnPoint; - public Transform runnerPrefab; - - private GameObject _runner; - public enum Zone { VALLEY, PLAINS, @@ -45,7 +41,11 @@ public class ResetZones : MonoBehaviour { currentZone = (Zone)newZone; } - private Vector3 GetRespawnPosition(Zone zone) { + public Zone GetCurrentZone() { + return currentZone; + } + + public Vector3 GetRespawnPosition(Zone zone) { switch(zone) { case Zone.PLAINS: return PlainsRespawnPoint.position; @@ -58,105 +58,4 @@ public class ResetZones : MonoBehaviour { return ValleyRespawnPoint.position; } } - - public void RespawnToCheckpoint() { - RespawnPlayerServerRPC(gameObject.transform.root.gameObject.GetComponent().OwnerClientId, GetRespawnPosition(currentZone)); - } - - [ServerRpc(RequireOwnership = false)] - private void RespawnPlayerServerRPC(ulong clientID, Vector3 respawnPos, ServerRpcParams serverRpcParams = default) - { - - // Get all players in the scene - GameObject[] playableCharacters = GameObject.FindGameObjectsWithTag("Player"); - - // Find our player first - foreach (GameObject character in playableCharacters) { - if (character.GetComponent().OwnerClientId == clientID) { - // Player found - - // Despawn them - try { - character.GetComponent().Despawn(true); - } catch (SpawnStateException e) { - Debug.LogError("Spawn State Exception Exception:"); - Debug.LogError(e); - return; - } - - // Spawn the player - if (ServerGameNetPortal.Instance.clientIdToGuid.TryGetValue(clientID, out string clientGuid)) { - if (ServerGameNetPortal.Instance.clientData.TryGetValue(clientGuid, out PlayerData playerData)) { - // Spawn as player - _runner = Instantiate(runnerPrefab, respawnPos, Quaternion.Euler(0, -90, 0)).gameObject; - _runner.GetComponent().SpawnAsPlayerObject(clientID, null, true); - - // Handle Client Spawning Locally - string itemsAsString = string.Join(",", playerData.pInv.NetworkItemList); - StartCoroutine(SpawnClient(clientID, itemsAsString)); - } - } - } - } - } - - // The client respawning needs a slight delay to allow for the spawn to properly sync up - IEnumerator SpawnClient(ulong clientID, string itemsAsString) { - - // First notify the player they are respawning (so we display stuff on screen) - ClientRpcParams clientRpcParams = new ClientRpcParams { - Send = new ClientRpcSendParams { - TargetClientIds = new ulong[] { clientID } - } - }; - - UIRespawningClientRpc(clientID, clientRpcParams); - - // 3 Second Respawn Delay - yield return new WaitForSecondsRealtime(3f); - - // Now actually respawn the player - clientRpcParams = new ClientRpcParams { - Send = new ClientRpcSendParams { - TargetClientIds = new ulong[] { clientID } - } - }; - - SpawnPlayerClientRpc(clientID, itemsAsString, clientRpcParams); - } - - [ClientRpc] - private void UIRespawningClientRpc(ulong clientId, ClientRpcParams clientRpcParams = default) { - GameObject.FindGameObjectWithTag("RunnerHUD").GetComponent().setRespawnPanelVisibility(true); - GameObject.FindGameObjectWithTag("RunnerHUD").GetComponent().countdown_text.enabled = false; - } - - // Spawn in each player - [ClientRpc] - public void SpawnPlayerClientRpc(ulong clientId, string itemsAsString, ClientRpcParams clientRpcParams = default) { - - GameObject[] playableCharacters = GameObject.FindGameObjectsWithTag("Player"); - - foreach (GameObject character in playableCharacters) { - if (character.GetComponent().OwnerClientId == clientId) { - // Rebuild inventory - List itemList = itemsAsString.Split(',').ToList(); - character.GetComponentInChildren().UpdateEquips(itemList, this.gameObject.GetComponent().ItemDict); - - GameHandler.FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent().enabled = true; - GameHandler.FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent().enabled = true; - GameHandler.FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent().enabled = true; - - character.GetComponentInChildren().enabled = true; - character.GetComponentInChildren().enabled = true; - character.GetComponentInChildren().enabled = true; - character.GetComponentInChildren().enabled = true; - character.GetComponentInChildren().enabled = true; - } - } - - // Also turn off the respawning UI and back on the UI for the timer - GameObject.FindGameObjectWithTag("RunnerHUD").GetComponent().setRespawnPanelVisibility(false); - GameObject.FindGameObjectWithTag("RunnerHUD").GetComponent().countdown_text.enabled = true; - } } diff --git a/Assets/Scripts/UI/PauseMenu.cs b/Assets/Scripts/UI/PauseMenu.cs index 5e4f90d..2b7166d 100644 --- a/Assets/Scripts/UI/PauseMenu.cs +++ b/Assets/Scripts/UI/PauseMenu.cs @@ -1,11 +1,13 @@ using System.Collections; using System.Collections.Generic; +using System.Linq; using MLAPI; +using MLAPI.Exceptions; using MLAPI.Messaging; using TMPro; using UnityEngine; -public class PauseMenu : MonoBehaviour { +public class PauseMenu : NetworkBehaviour { [SerializeField] private GameObject PauseMenuPanel; @@ -26,6 +28,10 @@ public class PauseMenu : MonoBehaviour { [SerializeField] private TMP_Text ControlsText; + public Transform runnerPrefab; + + private GameObject _runner; + private bool isViewingRunnerControls = true; void Start() { @@ -129,14 +135,116 @@ public class PauseMenu : MonoBehaviour { } public void RespawnConfirmed() { + // Disable/Enable player controls GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject player in players) { // Find the local player if (player.GetComponent().IsLocalPlayer) { - player.GetComponent().RespawnToCheckpoint(); + RespawnPlayerServerRPC(player.GetComponent().OwnerClientId, + player.GetComponentInChildren().GetRespawnPosition(player.GetComponentInChildren().GetCurrentZone())); + } + } + + // Turn off the pause menu + RespawnDecline(); + OnResumeGameClicked(); + } + + [ServerRpc(RequireOwnership = false)] + public void RespawnPlayerServerRPC(ulong clientID, Vector3 respawnPos, ServerRpcParams serverRpcParams = default) { + + // Get all players in the scene + GameObject[] playableCharacters = GameObject.FindGameObjectsWithTag("Player"); + + // Find our player first + foreach (GameObject character in playableCharacters) { + if (character.GetComponent().OwnerClientId == clientID) { + // Player found + + // Despawn them + try { + character.GetComponent().Despawn(true); + } catch (SpawnStateException e) { + Debug.LogError("Spawn State Exception Exception:"); + Debug.LogError(e); + return; + } + //DespawnPlayerServerRPC(clientID); + + // Spawn the player + if (ServerGameNetPortal.Instance.clientIdToGuid.TryGetValue(clientID, out string clientGuid)) { + if (ServerGameNetPortal.Instance.clientData.TryGetValue(clientGuid, out PlayerData playerData)) { + // Spawn as player + _runner = Instantiate(runnerPrefab, respawnPos, Quaternion.Euler(0, -90, 0)).gameObject; + _runner.GetComponent().SpawnAsPlayerObject(clientID, null, true); + + // Handle Client Spawning Locally + string itemsAsString = string.Join(",", playerData.pInv.NetworkItemList); + + StartCoroutine(SpawnClient(clientID, itemsAsString)); + } + } } } } + + // The client respawning needs a slight delay to allow for the spawn to properly sync up + IEnumerator SpawnClient(ulong clientID, string itemsAsString) { + // First notify the player they are respawning (so we display stuff on screen) + ClientRpcParams clientRpcParams = new ClientRpcParams { + Send = new ClientRpcSendParams { + TargetClientIds = new ulong[] { clientID } + } + }; + + UIRespawningClientRpc(clientID, clientRpcParams); + + // 3 Second Respawn Delay + yield return new WaitForSecondsRealtime(3f); + // Now actually respawn the player + clientRpcParams = new ClientRpcParams { + Send = new ClientRpcSendParams { + TargetClientIds = new ulong[] { clientID } + } + }; + + SpawnPlayerClientRpc(clientID, itemsAsString, clientRpcParams); + } + + [ClientRpc] + private void UIRespawningClientRpc(ulong clientId, ClientRpcParams clientRpcParams = default) + { + GameObject.FindGameObjectWithTag("RunnerHUD").GetComponent().setRespawnPanelVisibility(true); + GameObject.FindGameObjectWithTag("RunnerHUD").GetComponent().countdown_text.enabled = false; + } + + // Spawn in each player + [ClientRpc] + public void SpawnPlayerClientRpc(ulong clientId, string itemsAsString, ClientRpcParams clientRpcParams = default) { + GameObject[] playableCharacters = GameObject.FindGameObjectsWithTag("Player"); + + foreach (GameObject character in playableCharacters) { + if (character.GetComponent().OwnerClientId == clientId) { + // Rebuild inventory + List itemList = itemsAsString.Split(',').ToList(); + character.GetComponentInChildren().UpdateEquips(itemList, this.gameObject.GetComponent().ItemDict); + + GameHandler.FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent().enabled = true; + GameHandler.FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent().enabled = true; + GameHandler.FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent().enabled = true; + + character.GetComponentInChildren().enabled = true; + character.GetComponentInChildren().enabled = true; + character.GetComponentInChildren().enabled = true; + character.GetComponentInChildren().enabled = true; + character.GetComponentInChildren().enabled = true; + } + } + + // Also turn off the respawning UI and back on the UI for the timer + GameObject.FindGameObjectWithTag("RunnerHUD").GetComponent().setRespawnPanelVisibility(false); + GameObject.FindGameObjectWithTag("RunnerHUD").GetComponent().countdown_text.enabled = true; + } }