From 3ef7f7d0fbf703d6d19048f9a1d6d0cfdd4e079f Mon Sep 17 00:00:00 2001 From: Evan Nydahl Date: Mon, 14 Mar 2022 21:44:45 -0500 Subject: [PATCH] Fixed bug with ui on networked -chagne cool down script to call a function to populate player canvas -Added populate call to three network scripts --- .../Prefabs/Player/DebugPlayerPrefab 1.prefab | 11 +- .../Prefabs/Player/DebugSMPlayerPrefab.prefab | 3 +- .../Player/NetworkSMPlayerPrefab.prefab | 3 +- Assets/Scripts/CoolDown.cs | 225 +++++++++--------- Assets/Scripts/Environment/Pitfall.cs | 1 + Assets/Scripts/Network/Game/SpawnManager.cs | 4 +- Assets/Scripts/UI/PauseMenu.cs | 1 + 7 files changed, 130 insertions(+), 118 deletions(-) diff --git a/Assets/Prefabs/Player/DebugPlayerPrefab 1.prefab b/Assets/Prefabs/Player/DebugPlayerPrefab 1.prefab index ee650ad..05b19dc 100644 --- a/Assets/Prefabs/Player/DebugPlayerPrefab 1.prefab +++ b/Assets/Prefabs/Player/DebugPlayerPrefab 1.prefab @@ -3513,16 +3513,16 @@ Canvas: m_Enabled: 1 serializedVersion: 3 m_RenderMode: 1 - m_Camera: {fileID: 0} - m_PlaneDistance: 100 + m_Camera: {fileID: 2637749574256434612} + m_PlaneDistance: 1 m_PixelPerfect: 0 m_ReceivesEvents: 1 m_OverrideSorting: 0 m_OverridePixelPerfect: 0 m_SortingBucketNormalizedSize: 0 m_AdditionalShaderChannelsFlag: 25 - m_SortingLayerID: 0 - m_SortingOrder: 0 + m_SortingLayerID: 378093239 + m_SortingOrder: 10 m_TargetDisplay: 0 --- !u!114 &3458732709909940014 MonoBehaviour: @@ -3576,13 +3576,14 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 6c342edd8126e1449a50220a14c9333e, type: 3} m_Name: m_EditorClassIdentifier: - stats: {fileID: 0} + stats: {fileID: 6664667533527261801} uiPrebab: {fileID: 8588054010754274200, guid: e38204bb7b42b7642b974d9ee0c6903a, type: 3} dashItem: {fileID: 11400000, guid: 3156de54e455b4348b2a6e79383383b0, type: 2} nitroItem: {fileID: 11400000, guid: a1c26807795a7ac4f83567455ce978ce, type: 2} kickItem: {fileID: 11400000, guid: a96dfb1a70e0d0a4f84c15378f38ce99, type: 2} grapple: {fileID: 11400000, guid: 3c5f77adbd146274281d636352eb5018, type: 2} Glide: {fileID: 11400000, guid: 8fe830ac457225a4ab1031a499db94fc, type: 2} + boxHighlight: {fileID: 3445366865525666204} --- !u!1 &4973559418213200510 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Player/DebugSMPlayerPrefab.prefab b/Assets/Prefabs/Player/DebugSMPlayerPrefab.prefab index f8a7248..efd961b 100644 --- a/Assets/Prefabs/Player/DebugSMPlayerPrefab.prefab +++ b/Assets/Prefabs/Player/DebugSMPlayerPrefab.prefab @@ -4399,13 +4399,14 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 6c342edd8126e1449a50220a14c9333e, type: 3} m_Name: m_EditorClassIdentifier: - stats: {fileID: 0} + stats: {fileID: 1707207228499037468} uiPrebab: {fileID: 8588054010754274200, guid: e38204bb7b42b7642b974d9ee0c6903a, type: 3} dashItem: {fileID: 11400000, guid: 3156de54e455b4348b2a6e79383383b0, type: 2} nitroItem: {fileID: 11400000, guid: a1c26807795a7ac4f83567455ce978ce, type: 2} kickItem: {fileID: 11400000, guid: a96dfb1a70e0d0a4f84c15378f38ce99, type: 2} grapple: {fileID: 11400000, guid: 3c5f77adbd146274281d636352eb5018, type: 2} Glide: {fileID: 11400000, guid: 8fe830ac457225a4ab1031a499db94fc, type: 2} + boxHighlight: {fileID: 5070943905975734141} --- !u!1 &6955618578326703695 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Player/NetworkSMPlayerPrefab.prefab b/Assets/Prefabs/Player/NetworkSMPlayerPrefab.prefab index b232cf7..79bce22 100644 --- a/Assets/Prefabs/Player/NetworkSMPlayerPrefab.prefab +++ b/Assets/Prefabs/Player/NetworkSMPlayerPrefab.prefab @@ -2197,13 +2197,14 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 6c342edd8126e1449a50220a14c9333e, type: 3} m_Name: m_EditorClassIdentifier: - stats: {fileID: 0} + stats: {fileID: 7688428083034862287} uiPrebab: {fileID: 8588054010754274200, guid: e38204bb7b42b7642b974d9ee0c6903a, type: 3} dashItem: {fileID: 11400000, guid: 3156de54e455b4348b2a6e79383383b0, type: 2} nitroItem: {fileID: 11400000, guid: a1c26807795a7ac4f83567455ce978ce, type: 2} kickItem: {fileID: 11400000, guid: a96dfb1a70e0d0a4f84c15378f38ce99, type: 2} grapple: {fileID: 11400000, guid: 3c5f77adbd146274281d636352eb5018, type: 2} Glide: {fileID: 11400000, guid: 8fe830ac457225a4ab1031a499db94fc, type: 2} + boxHighlight: {fileID: 8092231625093547256} --- !u!1 &3010724135818471905 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/CoolDown.cs b/Assets/Scripts/CoolDown.cs index 7abf96a..9ba6229 100644 --- a/Assets/Scripts/CoolDown.cs +++ b/Assets/Scripts/CoolDown.cs @@ -17,119 +17,11 @@ public class CoolDown : MonoBehaviour public Item kickItem; public Item grapple; public Item Glide; - private GameObject boxHighlight; + public GameObject boxHighlight; // Start is called before the first frame update void Start(){ - //retrieve player object, find the T-Pose child, and then retrive player stats - stats = GameObject.FindGameObjectWithTag("Player").transform.Find("T-Pose").GetComponent(); - //retrieve box object - boxHighlight = this.transform.Find("Highlight").gameObject; - //apply special items (can condense and simplify if needed) - if(stats.HasNitro == true){ - GameObject temp = Instantiate(uiPrebab); - temp.transform.SetParent(this.gameObject.transform); - temp.name = nitroItem.name; - temp.transform.localRotation = Quaternion.identity; - temp.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); - temp.transform.localRotation.Set(0f, 0f, 0f, 0f); - temp.GetComponent().setCoolDownTime(nitroItem.cooldownM); - //set position on canvas - //due to low number, gonna hardcode this to be first - temp.transform.localPosition = new Vector3(-850, 425); - //set icon to ui icon - temp.transform.GetComponent().sprite = nitroItem.itemSprite; - //set button control (hard coded) - temp.transform.GetComponentInChildren().text = "Shift"; - } - if (stats.HasDash == true){ - GameObject temp2 = Instantiate(uiPrebab); - temp2.transform.SetParent(this.gameObject.transform); - temp2.name = dashItem.name; - temp2.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); - temp2.transform.localRotation = Quaternion.identity; - temp2.GetComponent().setCoolDownTime(dashItem.cooldownM); - - //set image - temp2.transform.GetComponent().sprite = dashItem.itemSprite; - - //if has nitro, make it below nitro icon - if (stats.HasNitro == true) - { - temp2.transform.localPosition = new Vector3(-850, 225); - } - //if not, make this icon top of screen - else{ - temp2.transform.localPosition = new Vector3(-850, 425); - } - //set button control - temp2.transform.GetComponentInChildren().text = "R"; - } - - ////display guranteed items - // temp pos var - float posTemp = 0f; - //kick - GameObject temp3 = Instantiate(uiPrebab); - //set parent as highlight - temp3.transform.SetParent(boxHighlight.transform); - temp3.name = kickItem.name; - temp3.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); - temp3.transform.localRotation = Quaternion.identity; - //due to low number, gonna hardcode this to be first - temp3.transform.localPosition = new Vector3(-100, -100); - //set icon to ui icon - temp3.transform.GetComponent().sprite = kickItem.itemSprite; - temp3.transform.GetComponentInChildren().text = "F"; - - //slide - GameObject temp4 = Instantiate(uiPrebab); - //set parent as highlight - temp4.transform.SetParent(boxHighlight.transform); - temp4.name = "slide"; - temp4.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); - temp4.transform.localRotation = Quaternion.identity; - //due to low number, gonna hardcode this to be first - temp4.transform.localPosition = new Vector3(100, -100); - //set icon to ui icon - //doesn't exists - temp4.transform.GetComponentInChildren().text = "Slide \n Q"; - - ////check if items are there - //grapple - if(stats.HasGrapple == true){ - GameObject temp5 = Instantiate(uiPrebab); - //set parent as highlight - temp5.transform.SetParent(boxHighlight.transform); - temp5.name = grapple.itemName; - temp5.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); - temp5.transform.localRotation = Quaternion.identity; - //due to low number, gonna hardcode this to be first - temp5.transform.localPosition = new Vector3(100 + posTemp, 100); - //set icon to ui icon - temp5.transform.GetComponent().sprite = grapple.itemSprite; - //doesn't exists - temp5.transform.GetComponentInChildren().text = "E"; - //increment counter - posTemp -= 200; - } - //glider - if(stats.HasGlider == true){ - GameObject temp6 = Instantiate(uiPrebab); - //set parent as highlight - temp6.transform.SetParent(boxHighlight.transform); - temp6.name = Glide.itemName; - temp6.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); - temp6.transform.localRotation = Quaternion.identity; - //due to low number, gonna hardcode this to be first - temp6.transform.localPosition = new Vector3(100 + posTemp, 100); - //set icon to ui icon - temp6.transform.GetComponent().sprite = Glide.itemSprite; - //doesn't exists - temp6.transform.GetComponentInChildren().text = "Hold Space"; - //increment counter - posTemp -= 200; - } + @@ -152,4 +44,117 @@ public class CoolDown : MonoBehaviour } } } + public void populatePlayerCanvas() + { + //apply special items (can condense and simplify if needed) + if (stats.HasNitro == true) + { + GameObject temp = Instantiate(uiPrebab); + temp.transform.SetParent(this.gameObject.transform); + temp.name = nitroItem.name; + temp.transform.localRotation = Quaternion.identity; + temp.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); + temp.transform.localRotation.Set(0f, 0f, 0f, 0f); + temp.GetComponent().setCoolDownTime(nitroItem.cooldownM); + //set position on canvas + //due to low number, gonna hardcode this to be first + temp.transform.localPosition = new Vector3(-850, 425); + //set icon to ui icon + temp.transform.GetComponent().sprite = nitroItem.itemSprite; + //set button control (hard coded) + temp.transform.GetComponentInChildren().text = "Shift"; + } + if (stats.HasDash == true) + { + GameObject temp2 = Instantiate(uiPrebab); + temp2.transform.SetParent(this.gameObject.transform); + temp2.name = dashItem.name; + temp2.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); + temp2.transform.localRotation = Quaternion.identity; + temp2.GetComponent().setCoolDownTime(dashItem.cooldownM); + + //set image + temp2.transform.GetComponent().sprite = dashItem.itemSprite; + + //if has nitro, make it below nitro icon + if (stats.HasNitro == true) + { + temp2.transform.localPosition = new Vector3(-850, 225); + } + //if not, make this icon top of screen + else + { + temp2.transform.localPosition = new Vector3(-850, 425); + } + //set button control + temp2.transform.GetComponentInChildren().text = "R"; + } + + ////display guranteed items + // temp pos var + float posTemp = 0f; + //kick + GameObject temp3 = Instantiate(uiPrebab); + //set parent as highlight + temp3.transform.SetParent(boxHighlight.transform); + temp3.name = kickItem.name; + temp3.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); + temp3.transform.localRotation = Quaternion.identity; + //due to low number, gonna hardcode this to be first + temp3.transform.localPosition = new Vector3(-100, -100); + //set icon to ui icon + temp3.transform.GetComponent().sprite = kickItem.itemSprite; + temp3.transform.GetComponentInChildren().text = "F"; + + //slide + GameObject temp4 = Instantiate(uiPrebab); + //set parent as highlight + temp4.transform.SetParent(boxHighlight.transform); + temp4.name = "slide"; + temp4.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); + temp4.transform.localRotation = Quaternion.identity; + //due to low number, gonna hardcode this to be first + temp4.transform.localPosition = new Vector3(100, -100); + //set icon to ui icon + //doesn't exists + temp4.transform.GetComponentInChildren().text = "Slide \n Q"; + + ////check if items are there + //grapple + if (stats.HasGrapple == true) + { + GameObject temp5 = Instantiate(uiPrebab); + //set parent as highlight + temp5.transform.SetParent(boxHighlight.transform); + temp5.name = grapple.itemName; + temp5.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); + temp5.transform.localRotation = Quaternion.identity; + //due to low number, gonna hardcode this to be first + temp5.transform.localPosition = new Vector3(100 + posTemp, 100); + //set icon to ui icon + temp5.transform.GetComponent().sprite = grapple.itemSprite; + //doesn't exists + temp5.transform.GetComponentInChildren().text = "E"; + //increment counter + posTemp -= 200; + } + //glider + if (stats.HasGlider == true) + { + GameObject temp6 = Instantiate(uiPrebab); + //set parent as highlight + temp6.transform.SetParent(boxHighlight.transform); + temp6.name = Glide.itemName; + temp6.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); + temp6.transform.localRotation = Quaternion.identity; + //due to low number, gonna hardcode this to be first + temp6.transform.localPosition = new Vector3(100 + posTemp, 100); + //set icon to ui icon + temp6.transform.GetComponent().sprite = Glide.itemSprite; + //doesn't exists + temp6.transform.GetComponentInChildren().text = "Hold Space"; + //increment counter + posTemp -= 200; + } + } } diff --git a/Assets/Scripts/Environment/Pitfall.cs b/Assets/Scripts/Environment/Pitfall.cs index 35e471c..0347da5 100644 --- a/Assets/Scripts/Environment/Pitfall.cs +++ b/Assets/Scripts/Environment/Pitfall.cs @@ -130,6 +130,7 @@ public class Pitfall : NetworkBehaviour character.GetComponentInChildren().enabled = true; character.GetComponentInChildren().enabled = true; character.GetComponentInChildren().enabled = true; + character.GetComponentInChildren().populatePlayerCanvas(); } } diff --git a/Assets/Scripts/Network/Game/SpawnManager.cs b/Assets/Scripts/Network/Game/SpawnManager.cs index d7e3986..7374298 100644 --- a/Assets/Scripts/Network/Game/SpawnManager.cs +++ b/Assets/Scripts/Network/Game/SpawnManager.cs @@ -38,8 +38,9 @@ public class SpawnManager : NetworkBehaviour { _runner = Instantiate(runnerPrefab, runnersSpawnPoints[runnersSpawned], Quaternion.Euler(0, -90, 0)).gameObject; //Recreate Inventory _runner.GetComponentInChildren().UpdateEquips(playerData.pInv.NetworkItemList, this.gameObject.GetComponent().ItemDict); + _runner.GetComponentInChildren().populatePlayerCanvas(); _runner.GetComponent().SpawnAsPlayerObject(NetworkManager.Singleton.LocalClientId, null, true); - + // Increment runners runnersSpawned++; } @@ -115,6 +116,7 @@ public class SpawnManager : NetworkBehaviour { List itemList = itemsAsString.Split(',').ToList(); character.GetComponentInChildren().UpdateEquips(itemList, this.gameObject.GetComponent().ItemDict); + character.GetComponentInChildren().populatePlayerCanvas(); } } } diff --git a/Assets/Scripts/UI/PauseMenu.cs b/Assets/Scripts/UI/PauseMenu.cs index 074817f..0466f8f 100644 --- a/Assets/Scripts/UI/PauseMenu.cs +++ b/Assets/Scripts/UI/PauseMenu.cs @@ -256,6 +256,7 @@ public class PauseMenu : NetworkBehaviour { character.GetComponentInChildren().enabled = true; character.GetComponentInChildren().enabled = true; character.GetComponentInChildren().enabled = true; + character.GetComponentInChildren().populatePlayerCanvas(); } }