Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. using UnityEngine.UI;
  6. using UnityEngine.Networking;
  7. using System.Linq;
  8. using TMPro;
  9. using UnityEditor;
  10. using UnityEditorInternal;
  11.  
  12.  
  13. public class ShopK : NetworkBehaviour {
  14.  
  15. public GameObject BoxFab, ItemFab;
  16. public Transform BoxHolder, WorldGO, ItemsHolder;
  17.  
  18. public List<GameObject> Items;
  19.  
  20. public ShopItems[] shopItems;
  21.  
  22. public TMP_Text ToPayToday;
  23.  
  24. public void Awake()
  25. {
  26. for (int i = 0; i < shopItems.Length; i++)
  27. {
  28. GameObject ab = (GameObject)Instantiate(ItemFab, ItemsHolder) as GameObject;
  29.  
  30. ab.transform.name = shopItems[i].Name;
  31.  
  32. ab.transform.GetChild(1).GetComponent<Image>().sprite = shopItems[i].Icon;
  33. ab.transform.GetChild(2).GetComponent<TMP_Text>().text = shopItems[i].Name;
  34. ab.transform.GetChild(3).GetComponent<TMP_Text>().text = shopItems[i].Description;
  35. ab.transform.GetChild(6).GetComponent<TMP_InputField>().text = shopItems[i].HowMany.ToString();
  36.  
  37. ab.transform.GetChild(2).GetComponent<TMP_Text>().fontSize = shopItems[i].NameSize;
  38. ab.transform.GetChild(3).GetComponent<TMP_Text>().fontSize = shopItems[i].DescrSize;
  39.  
  40. shopItems[i].IF = ab.transform.GetChild(6).GetComponent<TMP_InputField>();
  41.  
  42. if (shopItems[i].ItemFab != null)
  43. {
  44. ab.transform.GetChild(4).GetComponent<Button>().onClick.AddListener(() => Test11(shopItems[i].ItemFab));
  45. ab.transform.GetChild(5).GetComponent<Button>().onClick.AddListener(() => Test55(shopItems[i].ItemFab));
  46. ab.transform.GetChild(7).GetComponent<Button>().onClick.AddListener(() => Test5(shopItems[i].ItemFab));
  47. ab.transform.GetChild(8).GetComponent<Button>().onClick.AddListener(() => Test1(shopItems[i].ItemFab));
  48. } else
  49. {
  50. Debug.LogWarning("Something Went Wrong with the Buying Buttons!");
  51. }
  52.  
  53. }
  54. }
  55.  
  56. public void FixedUpdate()
  57. {
  58. for (int i = 0; i < shopItems.Length; i++)
  59. {
  60. shopItems[i].HowMany = Items.Where(x => x.gameObject == shopItems[i].ItemFab).ToArray().Length;
  61. shopItems[i].HowMany = Mathf.Clamp(shopItems[i].HowMany, 0f, 9f);
  62. shopItems[i].IF.text = shopItems[i].HowMany.ToString();
  63. }
  64. float hasToPay = 0f;
  65. for (int i = 0; i < shopItems.Length; i++)
  66. {
  67. hasToPay += shopItems[i].HowMany * shopItems[i].Price;
  68. }
  69. ToPayToday.text = "Costs: " + hasToPay.ToString();
  70. }
  71.  
  72. public void Test1(GameObject Item)
  73. {
  74. if (Items.Where(x => x.gameObject == Item).ToArray().Length >= 9f)
  75. return;
  76. Items.Add(Item);
  77. }
  78.  
  79. public void Test11(GameObject Item)
  80. {
  81. if (Items.Where(x => x.gameObject == Item).ToArray().Length >= 1f)
  82. Items.Remove(Item);
  83. }
  84.  
  85. public void Test5(GameObject Item)
  86. {
  87. if (Items.Where(x => x.gameObject == Item).ToArray().Length >= 6f)
  88. return;
  89. Items.Add(Item);
  90. Items.Add(Item);
  91. Items.Add(Item);
  92. Items.Add(Item);
  93. Items.Add(Item);
  94. }
  95.  
  96. public void Test55(GameObject Item)
  97. {
  98. if (Items.Where(x => x.gameObject == Item).ToArray().Length >= 5f)
  99. {
  100. Items.Remove(Item);
  101. Items.Remove(Item);
  102. Items.Remove(Item);
  103. Items.Remove(Item);
  104. Items.Remove(Item);
  105. }
  106. }
  107.  
  108. [Command]
  109. public void CmdSpawnBox()
  110. {
  111. float AmountOfFurniture = 0f;
  112. for (int i = 0; i < shopItems.Length; i++)
  113. {
  114. AmountOfFurniture += shopItems[i].HowMany;
  115. }
  116.  
  117. if (AmountOfFurniture == 0)
  118. return;
  119.  
  120. GameObject abc = (GameObject)Instantiate(BoxFab, BoxHolder.position, Quaternion.identity, BoxHolder) as GameObject;
  121. NetworkServer.Spawn(abc);
  122. abc.gameObject.GetComponent<UnboxingBox>().List = Items;
  123. abc.gameObject.GetComponent<UnboxingBox>().WorldGO = WorldGO;
  124. Items = new List<GameObject>();
  125. for (int i = 0; i < shopItems.Length; i++)
  126. {
  127. shopItems[i].HowMany = 0f;
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement