Simple Buy Item Logic
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Threading;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Client : MonoBehaviour
|
||||
{
|
||||
@@ -27,6 +28,7 @@ public class Client : MonoBehaviour
|
||||
[SerializeField] private GameObject[] playerInfo;
|
||||
private PlayerInfoElements[] playerInfoElements = new PlayerInfoElements[4];
|
||||
[SerializeField] private GameObject layout2;
|
||||
[SerializeField] private Image[] uiItems;
|
||||
|
||||
private int playerAmount = 0;
|
||||
|
||||
@@ -182,6 +184,18 @@ public class Client : MonoBehaviour
|
||||
players[job.data[1]].uiHandler = uiHandler;
|
||||
players[job.data[1]].textLeftMoves = textLeftMoves;
|
||||
players[job.data[1]].AddCoins(3);
|
||||
|
||||
Image[] tempUIItems = new Image[3];
|
||||
|
||||
int f = 0;
|
||||
|
||||
for (int i = job.data[1] * 3; i < job.data[1] * 3 + 3; i++)
|
||||
{
|
||||
tempUIItems[f] = uiItems[i];
|
||||
}
|
||||
|
||||
players[job.data[1]].uiItems = tempUIItems;
|
||||
|
||||
players[job.data[1]].Init();
|
||||
|
||||
playerNameTexts[job.data[1]].text = Encoding.ASCII.GetString(name).Replace(" ", "");
|
||||
@@ -281,4 +295,6 @@ public class Client : MonoBehaviour
|
||||
{
|
||||
stream.Write(new byte[]{8, 0, 0, 0, 0, 0, 0, 0, 0, 0});
|
||||
}
|
||||
|
||||
//TODO: SendBuyItem
|
||||
}
|
||||
@@ -4,8 +4,12 @@ using UnityEngine;
|
||||
|
||||
public class ItemShop : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject Layout2;
|
||||
[SerializeField] private GameObject LayoutItemShop;
|
||||
[SerializeField] private Client client;
|
||||
|
||||
[SerializeField] private UIItem[] items;
|
||||
|
||||
public static Player currentPlayer = null;
|
||||
|
||||
public void Init(Player _currentPlayer)
|
||||
{
|
||||
currentPlayer = _currentPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 143fbc3928a7403f94f31a42796f7c0c
|
||||
timeCreated: 1677790192
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Item : MonoBehaviour
|
||||
{
|
||||
public Sprite sprite;
|
||||
public Type type;
|
||||
|
||||
public int Cost
|
||||
{
|
||||
get
|
||||
{
|
||||
return cost;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] private int cost;
|
||||
|
||||
public enum Type
|
||||
{
|
||||
Mushroom = 0, DoubleDice = 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b369e867ce7bd2944baef65e2537086c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIItem : MonoBehaviour
|
||||
{
|
||||
public Item item;
|
||||
|
||||
public void BuyItem()
|
||||
{
|
||||
Player player = ItemShop.currentPlayer;
|
||||
|
||||
if (player.coins - item.Cost >= 0)
|
||||
{
|
||||
player.AddCoins(-item.Cost);
|
||||
UIHandler.GetInstance().ButtonBack();
|
||||
player.AddItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2133c87b176066c42bf8ebee13208124
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public abstract class Player : MonoBehaviour
|
||||
{
|
||||
@@ -20,6 +21,8 @@ public abstract class Player : MonoBehaviour
|
||||
public TMP_Text textCoinsInfo, textStarsInfo, textLeftMoves;
|
||||
protected bool eventstop = false;
|
||||
public UIHandler uiHandler;
|
||||
public Item[] items = new Item[3];
|
||||
public Image[] uiItems;
|
||||
|
||||
//for coin animation
|
||||
private AnimationHandler animationHandler;
|
||||
@@ -72,6 +75,19 @@ public abstract class Player : MonoBehaviour
|
||||
PlayAnimation(AnimationType.Coin);
|
||||
Client.GetCurrentInstance().CalculatePlacement();
|
||||
}
|
||||
|
||||
public void AddItem(Item item)
|
||||
{
|
||||
for (int i = 0; i < items.Length; i++)
|
||||
{
|
||||
if (items[i] == null)
|
||||
{
|
||||
items[i] = item;
|
||||
uiItems[i].sprite = item.sprite;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTriggerEnter(Collider c)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,15 @@ public class UIHandler : MonoBehaviour
|
||||
[SerializeField] private GameObject layout2;
|
||||
[SerializeField] private GameObject layoutMiniMap;
|
||||
[SerializeField] private GameObject layoutBuyStar;
|
||||
[SerializeField] private GameObject layoutItemShop;
|
||||
|
||||
private static UIHandler currentInstance;
|
||||
|
||||
public static UIHandler GetInstance()
|
||||
{
|
||||
return currentInstance;
|
||||
}
|
||||
|
||||
public bool MapOpen
|
||||
{
|
||||
get
|
||||
@@ -28,7 +36,9 @@ public class UIHandler : MonoBehaviour
|
||||
layoutMiniMap.SetActive(false);
|
||||
layoutBuyStar.SetActive(false);
|
||||
layout2.SetActive(false);
|
||||
|
||||
layoutItemShop.SetActive(false);
|
||||
|
||||
currentInstance = this;
|
||||
}
|
||||
|
||||
public void ActivateLayout1()
|
||||
@@ -38,6 +48,7 @@ public class UIHandler : MonoBehaviour
|
||||
layoutMiniMap.SetActive(false);
|
||||
layoutBuyStar.SetActive(false);
|
||||
layout2.SetActive(false);
|
||||
layoutItemShop.SetActive(false);
|
||||
}
|
||||
|
||||
public void ActivateLayoutMiniMap()
|
||||
@@ -47,6 +58,7 @@ public class UIHandler : MonoBehaviour
|
||||
layoutMiniMap.SetActive(true);
|
||||
layoutBuyStar.SetActive(false);
|
||||
layout2.SetActive(false);
|
||||
layoutItemShop.SetActive(false);
|
||||
}
|
||||
|
||||
public void ActivateLayoutBuyStar(Player player)
|
||||
@@ -57,6 +69,7 @@ public class UIHandler : MonoBehaviour
|
||||
layoutMiniMap.SetActive(false);
|
||||
layoutBuyStar.SetActive(true);
|
||||
layout2.SetActive(false);
|
||||
layoutItemShop.SetActive(false);
|
||||
|
||||
LayoutBuyStarController controller = layoutBuyStar.GetComponent<LayoutBuyStarController>();
|
||||
|
||||
@@ -81,6 +94,18 @@ public class UIHandler : MonoBehaviour
|
||||
layoutMiniMap.SetActive(false);
|
||||
layoutBuyStar.SetActive(false);
|
||||
layout2.SetActive(true);
|
||||
layoutItemShop.SetActive(false);
|
||||
}
|
||||
|
||||
public void ActivateLayoutItemShop()
|
||||
{
|
||||
layout0.SetActive(false);
|
||||
layout1.SetActive(false);
|
||||
layoutMiniMap.SetActive(false);
|
||||
layoutBuyStar.SetActive(false);
|
||||
layout2.SetActive(false);
|
||||
layoutItemShop.SetActive(true);
|
||||
layoutItemShop.GetComponent<ItemShop>().Init(currentPlayer);
|
||||
}
|
||||
|
||||
public void ButtonBuyStar()
|
||||
@@ -103,6 +128,12 @@ public class UIHandler : MonoBehaviour
|
||||
|
||||
public void ButtonEnter()
|
||||
{
|
||||
|
||||
ActivateLayoutItemShop();
|
||||
}
|
||||
|
||||
public void ButtonBack()
|
||||
{
|
||||
ActivateLayout1();
|
||||
((PlayablePlayer)currentPlayer).SkipShop();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user