Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- using System.Linq;
- using TMPro;
- using UnityEditor;
- using UnityEditorInternal;
- public class ShopK : NetworkBehaviour {
- public GameObject BoxFab, ItemFab;
- public Transform BoxHolder, WorldGO, ItemsHolder;
- public List<GameObject> Items;
- public ShopItems[] shopItems;
- public TMP_Text ToPayToday;
- public void Awake()
- {
- for (int i = 0; i < shopItems.Length; i++)
- {
- GameObject ab = (GameObject)Instantiate(ItemFab, ItemsHolder) as GameObject;
- ab.transform.name = shopItems[i].Name;
- ab.transform.GetChild(1).GetComponent<Image>().sprite = shopItems[i].Icon;
- ab.transform.GetChild(2).GetComponent<TMP_Text>().text = shopItems[i].Name;
- ab.transform.GetChild(3).GetComponent<TMP_Text>().text = shopItems[i].Description;
- ab.transform.GetChild(6).GetComponent<TMP_InputField>().text = shopItems[i].HowMany.ToString();
- ab.transform.GetChild(2).GetComponent<TMP_Text>().fontSize = shopItems[i].NameSize;
- ab.transform.GetChild(3).GetComponent<TMP_Text>().fontSize = shopItems[i].DescrSize;
- shopItems[i].IF = ab.transform.GetChild(6).GetComponent<TMP_InputField>();
- if (shopItems[i].ItemFab != null)
- {
- ab.transform.GetChild(4).GetComponent<Button>().onClick.AddListener(() => Test11(shopItems[i].ItemFab));
- ab.transform.GetChild(5).GetComponent<Button>().onClick.AddListener(() => Test55(shopItems[i].ItemFab));
- ab.transform.GetChild(7).GetComponent<Button>().onClick.AddListener(() => Test5(shopItems[i].ItemFab));
- ab.transform.GetChild(8).GetComponent<Button>().onClick.AddListener(() => Test1(shopItems[i].ItemFab));
- } else
- {
- Debug.LogWarning("Something Went Wrong with the Buying Buttons!");
- }
- }
- }
- public void FixedUpdate()
- {
- for (int i = 0; i < shopItems.Length; i++)
- {
- shopItems[i].HowMany = Items.Where(x => x.gameObject == shopItems[i].ItemFab).ToArray().Length;
- shopItems[i].HowMany = Mathf.Clamp(shopItems[i].HowMany, 0f, 9f);
- shopItems[i].IF.text = shopItems[i].HowMany.ToString();
- }
- float hasToPay = 0f;
- for (int i = 0; i < shopItems.Length; i++)
- {
- hasToPay += shopItems[i].HowMany * shopItems[i].Price;
- }
- ToPayToday.text = "Costs: " + hasToPay.ToString();
- }
- public void Test1(GameObject Item)
- {
- if (Items.Where(x => x.gameObject == Item).ToArray().Length >= 9f)
- return;
- Items.Add(Item);
- }
- public void Test11(GameObject Item)
- {
- if (Items.Where(x => x.gameObject == Item).ToArray().Length >= 1f)
- Items.Remove(Item);
- }
- public void Test5(GameObject Item)
- {
- if (Items.Where(x => x.gameObject == Item).ToArray().Length >= 6f)
- return;
- Items.Add(Item);
- Items.Add(Item);
- Items.Add(Item);
- Items.Add(Item);
- Items.Add(Item);
- }
- public void Test55(GameObject Item)
- {
- if (Items.Where(x => x.gameObject == Item).ToArray().Length >= 5f)
- {
- Items.Remove(Item);
- Items.Remove(Item);
- Items.Remove(Item);
- Items.Remove(Item);
- Items.Remove(Item);
- }
- }
- [Command]
- public void CmdSpawnBox()
- {
- float AmountOfFurniture = 0f;
- for (int i = 0; i < shopItems.Length; i++)
- {
- AmountOfFurniture += shopItems[i].HowMany;
- }
- if (AmountOfFurniture == 0)
- return;
- GameObject abc = (GameObject)Instantiate(BoxFab, BoxHolder.position, Quaternion.identity, BoxHolder) as GameObject;
- NetworkServer.Spawn(abc);
- abc.gameObject.GetComponent<UnboxingBox>().List = Items;
- abc.gameObject.GetComponent<UnboxingBox>().WorldGO = WorldGO;
- Items = new List<GameObject>();
- for (int i = 0; i < shopItems.Length; i++)
- {
- shopItems[i].HowMany = 0f;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement