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
This commit is contained in:
Evan Nydahl
2022-03-14 21:44:45 -05:00
parent 60e3213d41
commit 3ef7f7d0fb
7 changed files with 130 additions and 118 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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<PlayerStats>();
//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<UICoolDown>().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<Image>().sprite = nitroItem.itemSprite;
//set button control (hard coded)
temp.transform.GetComponentInChildren<TMPro.TextMeshProUGUI>().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<UICoolDown>().setCoolDownTime(dashItem.cooldownM);
//set image
temp2.transform.GetComponent<Image>().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<TMPro.TextMeshProUGUI>().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<Image>().sprite = kickItem.itemSprite;
temp3.transform.GetComponentInChildren<TMPro.TextMeshProUGUI>().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<TMPro.TextMeshProUGUI>().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<Image>().sprite = grapple.itemSprite;
//doesn't exists
temp5.transform.GetComponentInChildren<TMPro.TextMeshProUGUI>().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<Image>().sprite = Glide.itemSprite;
//doesn't exists
temp6.transform.GetComponentInChildren<TMPro.TextMeshProUGUI>().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<UICoolDown>().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<Image>().sprite = nitroItem.itemSprite;
//set button control (hard coded)
temp.transform.GetComponentInChildren<TMPro.TextMeshProUGUI>().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<UICoolDown>().setCoolDownTime(dashItem.cooldownM);
//set image
temp2.transform.GetComponent<Image>().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<TMPro.TextMeshProUGUI>().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<Image>().sprite = kickItem.itemSprite;
temp3.transform.GetComponentInChildren<TMPro.TextMeshProUGUI>().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<TMPro.TextMeshProUGUI>().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<Image>().sprite = grapple.itemSprite;
//doesn't exists
temp5.transform.GetComponentInChildren<TMPro.TextMeshProUGUI>().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<Image>().sprite = Glide.itemSprite;
//doesn't exists
temp6.transform.GetComponentInChildren<TMPro.TextMeshProUGUI>().text = "Hold Space";
//increment counter
posTemp -= 200;
}
}
}

View File

@@ -130,6 +130,7 @@ public class Pitfall : NetworkBehaviour
character.GetComponentInChildren<NitroStateManager>().enabled = true;
character.GetComponentInChildren<AerialStateManager>().enabled = true;
character.GetComponentInChildren<OffenseStateManager>().enabled = true;
character.GetComponentInChildren<CoolDown>().populatePlayerCanvas();
}
}

View File

@@ -38,8 +38,9 @@ public class SpawnManager : NetworkBehaviour {
_runner = Instantiate(runnerPrefab, runnersSpawnPoints[runnersSpawned], Quaternion.Euler(0, -90, 0)).gameObject;
//Recreate Inventory
_runner.GetComponentInChildren<PlayerInventory>().UpdateEquips(playerData.pInv.NetworkItemList, this.gameObject.GetComponent<InventoryManager>().ItemDict);
_runner.GetComponentInChildren<CoolDown>().populatePlayerCanvas();
_runner.GetComponent<NetworkObject>().SpawnAsPlayerObject(NetworkManager.Singleton.LocalClientId, null, true);
// Increment runners
runnersSpawned++;
}
@@ -115,6 +116,7 @@ public class SpawnManager : NetworkBehaviour {
List<string> itemList = itemsAsString.Split(',').ToList();
character.GetComponentInChildren<PlayerInventory>().UpdateEquips(itemList, this.gameObject.GetComponent<InventoryManager>().ItemDict);
character.GetComponentInChildren<CoolDown>().populatePlayerCanvas();
}
}
}

View File

@@ -256,6 +256,7 @@ public class PauseMenu : NetworkBehaviour {
character.GetComponentInChildren<NitroStateManager>().enabled = true;
character.GetComponentInChildren<AerialStateManager>().enabled = true;
character.GetComponentInChildren<OffenseStateManager>().enabled = true;
character.GetComponentInChildren<CoolDown>().populatePlayerCanvas();
}
}