Merge branch 'ResetButton'

This commit is contained in:
Julia Butenhoff 2022-02-28 14:07:46 -06:00
commit ad30ba0140
11 changed files with 1475 additions and 1 deletions

View File

@ -10,6 +10,7 @@ GameObject:
m_Component:
- component: {fileID: 8044612620057779272}
- component: {fileID: 8044612620057779273}
- component: {fileID: -2884972987869746759}
m_Layer: 0
m_Name: ResetZoneFoothills
m_TagString: Untagged
@ -44,3 +45,16 @@ BoxCollider:
serializedVersion: 2
m_Size: {x: 1700, y: 2000, z: 1200}
m_Center: {x: -2850, y: 0, z: 500}
--- !u!114 &-2884972987869746759
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8044612620057779274}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6560db454bf09ef49bdb0240a370b8aa, type: 3}
m_Name:
m_EditorClassIdentifier:
RespawnZone: 2

View File

@ -10,6 +10,7 @@ GameObject:
m_Component:
- component: {fileID: 8977215705378820474}
- component: {fileID: 8977215705378820485}
- component: {fileID: -3220977901539271234}
m_Layer: 0
m_Name: ResetZoneMountain
m_TagString: Untagged
@ -44,3 +45,16 @@ BoxCollider:
serializedVersion: 2
m_Size: {x: 1400, y: 2500, z: 1200}
m_Center: {x: -4400, y: 0, z: 500}
--- !u!114 &-3220977901539271234
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8977215705378820484}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6560db454bf09ef49bdb0240a370b8aa, type: 3}
m_Name:
m_EditorClassIdentifier:
RespawnZone: 3

View File

@ -10,6 +10,7 @@ GameObject:
m_Component:
- component: {fileID: 1578817158580045979}
- component: {fileID: 1578817158580045978}
- component: {fileID: -4917741327760879080}
m_Layer: 0
m_Name: ResetZonePlains
m_TagString: Untagged
@ -44,3 +45,16 @@ BoxCollider:
serializedVersion: 2
m_Size: {x: 2000, y: 1000, z: 1200}
m_Center: {x: -1000, y: 0, z: 500}
--- !u!114 &-4917741327760879080
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1578817158580045977}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6560db454bf09ef49bdb0240a370b8aa, type: 3}
m_Name:
m_EditorClassIdentifier:
RespawnZone: 1

View File

@ -10,6 +10,7 @@ GameObject:
m_Component:
- component: {fileID: 6676345594231214399}
- component: {fileID: 6676345594231214396}
- component: {fileID: -7956066325359681501}
m_Layer: 0
m_Name: ResetZoneValley
m_TagString: Untagged
@ -44,3 +45,16 @@ BoxCollider:
serializedVersion: 2
m_Size: {x: 1200, y: 1000, z: 1200}
m_Center: {x: 600, y: 0, z: 500}
--- !u!114 &-7956066325359681501
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6676345594231214397}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6560db454bf09ef49bdb0240a370b8aa, type: 3}
m_Name:
m_EditorClassIdentifier:
RespawnZone: 0

File diff suppressed because it is too large Load Diff

View File

@ -4597,6 +4597,7 @@ GameObject:
- component: {fileID: 7688428083034862389}
- component: {fileID: 7688428083034862390}
- component: {fileID: 7688428083034862391}
- component: {fileID: 7391821093297401085}
m_Layer: 0
m_Name: T-Pose
m_TagString: ArcherTarget
@ -4906,6 +4907,18 @@ MonoBehaviour:
pStats: {fileID: 0}
mSM: {fileID: 0}
aSM: {fileID: 0}
--- !u!114 &7391821093297401085
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7688428083034862386}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4f942eeaa888c98468c9ad196fb88115, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &7740096766088430285
GameObject:
m_ObjectHideFlags: 0

View File

@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MLAPI;
using MLAPI.Messaging;
public class ResetZonesGlobal : MonoBehaviour {
private bool cooldown = false;
[SerializeField]
private int RespawnZone;
private void OnTriggerEnter(Collider other) {
if (cooldown == false && other.transform.gameObject.tag == "PlayerTrigger" && other.gameObject.transform.root.gameObject.GetComponent<NetworkObject>().OwnerClientId == NetworkManager.Singleton.LocalClientId) {
SetClientRespawnZoneServerRPC(other.gameObject.transform.root.gameObject.GetComponent<NetworkObject>().OwnerClientId, RespawnZone);
cooldown = true;
StartCoroutine(CoolItDown());
}
}
[ServerRpc(RequireOwnership = false)]
private void SetClientRespawnZoneServerRPC(ulong clientID, int RespawnZone) {
SetClientRespawnZoneClientRPC(clientID, RespawnZone);
}
[ClientRpc]
private void SetClientRespawnZoneClientRPC(ulong clientID, int RespawnZone) {
// Get all players in the scene
GameObject[] playableCharacters = GameObject.FindGameObjectsWithTag("Player");
// Find our player first
foreach (GameObject character in playableCharacters) {
if (character.GetComponent<NetworkObject>().OwnerClientId == clientID) {
// Set their zone
character.GetComponent<ResetZones>().SetCurrentZone(RespawnZone);
}
}
}
IEnumerator CoolItDown() {
yield return new WaitForSecondsRealtime(1f);
cooldown = false;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6560db454bf09ef49bdb0240a370b8aa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,162 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using MLAPI;
using MLAPI.Messaging;
using MLAPI.Exceptions;
using System.Linq;
public class ResetZones : MonoBehaviour {
private Transform ValleyRespawnPoint;
private Transform PlainsRespawnPoint;
private Transform FoothillsRespawnPoint;
private Transform MountainRespawnPoint;
public Transform runnerPrefab;
private GameObject _runner;
public enum Zone {
VALLEY,
PLAINS,
FOOTHILLS,
MOUNTAIN
}
private Zone currentZone;
void Start() {
// Make sure we are in the game scene
if (SceneManager.GetActiveScene().buildIndex == 3) {
ValleyRespawnPoint = GameObject.FindGameObjectWithTag("ValleyRespawnPoint").transform;
PlainsRespawnPoint = GameObject.FindGameObjectWithTag("PlainsRespawnPoint").transform;
FoothillsRespawnPoint = GameObject.FindGameObjectWithTag("FoothillsRespawnPoint").transform;
MountainRespawnPoint = GameObject.FindGameObjectWithTag("MountainRespawnPoint").transform;
}
// Starting zone is the valley
currentZone = Zone.VALLEY;
}
public void SetCurrentZone(int newZone) {
currentZone = (Zone)newZone;
}
private Vector3 GetRespawnPosition(Zone zone) {
switch(zone) {
case Zone.PLAINS:
return PlainsRespawnPoint.position;
case Zone.FOOTHILLS:
return FoothillsRespawnPoint.position;
case Zone.MOUNTAIN:
return MountainRespawnPoint.position;
default:
case Zone.VALLEY:
return ValleyRespawnPoint.position;
}
}
public void RespawnToCheckpoint() {
RespawnPlayerServerRPC(gameObject.transform.root.gameObject.GetComponent<NetworkObject>().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<NetworkObject>().OwnerClientId == clientID) {
// Player found
// Despawn them
try {
character.GetComponent<NetworkObject>().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<NetworkObject>().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<PlayerHUD>().setRespawnPanelVisibility(true);
GameObject.FindGameObjectWithTag("RunnerHUD").GetComponent<PlayerHUD>().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<NetworkObject>().OwnerClientId == clientId) {
// Rebuild inventory
List<string> itemList = itemsAsString.Split(',').ToList();
character.GetComponentInChildren<PlayerInventory>().UpdateEquips(itemList, this.gameObject.GetComponent<InventoryManager>().ItemDict);
GameHandler.FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent<Camera>().enabled = true;
GameHandler.FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent<AudioListener>().enabled = true;
GameHandler.FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent<PlayerCam>().enabled = true;
character.GetComponentInChildren<MoveStateManager>().enabled = true;
character.GetComponentInChildren<DashStateManager>().enabled = true;
character.GetComponentInChildren<NitroStateManager>().enabled = true;
character.GetComponentInChildren<AerialStateManager>().enabled = true;
character.GetComponentInChildren<OffenseStateManager>().enabled = true;
}
}
// Also turn off the respawning UI and back on the UI for the timer
GameObject.FindGameObjectWithTag("RunnerHUD").GetComponent<PlayerHUD>().setRespawnPanelVisibility(false);
GameObject.FindGameObjectWithTag("RunnerHUD").GetComponent<PlayerHUD>().countdown_text.enabled = true;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4f942eeaa888c98468c9ad196fb88115
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -16,6 +16,9 @@ public class PauseMenu : MonoBehaviour {
[SerializeField]
private GameObject ConfirmationPanel;
[SerializeField]
private GameObject RespawnConfirmationPanel;
[SerializeField]
private TMP_Text ControlsHeader;
[SerializeField]
@ -29,6 +32,7 @@ public class PauseMenu : MonoBehaviour {
PauseMenuPanel.SetActive(false);
ControlsPanel.SetActive(false);
ConfirmationPanel.SetActive(false);
RespawnConfirmationPanel.SetActive(false);
}
void Update() {
@ -127,4 +131,24 @@ public class PauseMenu : MonoBehaviour {
ControlsText.text = "To-Do: Put the Runner's Controls here";
}
}
public void OnRespawnClicked() {
RespawnConfirmationPanel.SetActive(true);
}
public void RespawnDecline() {
RespawnConfirmationPanel.SetActive(false);
}
public void RespawnConfirmed() {
// Disable/Enable player controls
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
foreach (GameObject player in players) {
// Find the local player
if (player.GetComponent<NetworkObject>().IsLocalPlayer) {
player.GetComponent<ResetZones>().RespawnToCheckpoint();
}
}
}
}