Item Selector

This commit is contained in:
brausjonas
2023-03-04 01:14:26 +01:00
parent fd0a36ccb7
commit 194a84ad01
9 changed files with 1063 additions and 8 deletions
@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ItemSelector : MonoBehaviour
{
[SerializeField] private GameObject[] itemButtons;
[SerializeField] private Image[] itemImages;
public void Init(Item[] items)
{
for (int i = 0; i < items.Length; i++)
{
if (items[i] != null)
{
itemButtons[i].SetActive(true);
itemImages[i].sprite = items[i].sprite;
}
else
{
itemButtons[i].SetActive(false);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0eebc4bee1ee3be48bb72d5aefe33a57
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -28,6 +28,8 @@ public class PlayablePlayer : Player
public Client client;
private static PlayablePlayer instance;
public override void Init()
{
TMP_Text[] playerTexts = GetComponentsInChildren<TMP_Text>();
@@ -37,9 +39,15 @@ public class PlayablePlayer : Player
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = 61;
diceScript = dice.GetComponent<Dice>();
instance = this;
}
public static PlayablePlayer GetCurrentInstance()
{
return instance;
}
private void Update()
{
/*
+2 -2
View File
@@ -91,11 +91,11 @@ public abstract class Player : MonoBehaviour
}
}
public void ActivateItem(int index, Item.Type type)
public void ActivateItem(int index)
{
activeItem = items[index].type;
uiItems[index].gameObject.SetActive(false);
items[index] = null;
activeItem = type;
}
public void OnTriggerEnter(Collider c)
+30 -2
View File
@@ -11,6 +11,7 @@ public class UIHandler : MonoBehaviour
[SerializeField] private GameObject layoutMiniMap;
[SerializeField] private GameObject layoutBuyStar;
[SerializeField] private GameObject layoutItemShop;
[SerializeField] private GameObject layoutSelectItem;
private static UIHandler currentInstance;
@@ -37,6 +38,7 @@ public class UIHandler : MonoBehaviour
layoutBuyStar.SetActive(false);
layout2.SetActive(false);
layoutItemShop.SetActive(false);
layoutSelectItem.SetActive(false);
currentInstance = this;
}
@@ -49,6 +51,7 @@ public class UIHandler : MonoBehaviour
layoutBuyStar.SetActive(false);
layout2.SetActive(false);
layoutItemShop.SetActive(false);
layoutSelectItem.SetActive(false);
}
public void ActivateLayoutMiniMap()
@@ -59,6 +62,7 @@ public class UIHandler : MonoBehaviour
layoutBuyStar.SetActive(false);
layout2.SetActive(false);
layoutItemShop.SetActive(false);
layoutSelectItem.SetActive(false);
}
public void ActivateLayoutBuyStar(Player player)
@@ -70,6 +74,7 @@ public class UIHandler : MonoBehaviour
layoutBuyStar.SetActive(true);
layout2.SetActive(false);
layoutItemShop.SetActive(false);
layoutSelectItem.SetActive(false);
LayoutBuyStarController controller = layoutBuyStar.GetComponent<LayoutBuyStarController>();
@@ -95,6 +100,7 @@ public class UIHandler : MonoBehaviour
layoutBuyStar.SetActive(false);
layout2.SetActive(true);
layoutItemShop.SetActive(false);
layoutSelectItem.SetActive(false);
}
public void ActivateLayoutItemShop()
@@ -106,12 +112,28 @@ public class UIHandler : MonoBehaviour
layout2.SetActive(false);
layoutItemShop.SetActive(true);
layoutItemShop.GetComponent<ItemShop>().Init(currentPlayer);
layoutSelectItem.SetActive(false);
}
//TODO: Only temp, make additional function for Item selection
public void ActivateLayoutItemSelect()
{
currentPlayer.ActivateItem(0, Item.Type.Mushroom);
currentPlayer = PlayablePlayer.GetCurrentInstance();
if(currentPlayer.activated)
{
layout0.SetActive(false);
layout1.SetActive(false);
layoutMiniMap.SetActive(false);
layoutBuyStar.SetActive(false);
layout2.SetActive(false);
layoutItemShop.SetActive(false);
layoutSelectItem.GetComponent<ItemSelector>().Init(currentPlayer.items);
layoutSelectItem.SetActive(true);
}
}
public void ButtonBuyStar()
@@ -142,4 +164,10 @@ public class UIHandler : MonoBehaviour
ActivateLayout1();
((PlayablePlayer)currentPlayer).SkipShop();
}
public void ButtonSelectItem(int index)
{
currentPlayer.ActivateItem(index);
ActivateLayout1();
}
}