Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.Events;
  6. using UnityEngine.EventSystems;
  7. public class DropInventory : MonoBehaviour
  8. {
  9.  
  10. [Header("Отвечает за тип предметов ")]
  11. [SerializeField]
  12. int IdItems;
  13.  
  14. public Transform PanelForIcons;
  15.  
  16. public Weapon[] Weapons;
  17.  
  18. public KeysCar[] Car;
  19.  
  20. [SerializeField] string[] TypeWeapons;
  21.  
  22. [SerializeField] GameObject[] SpawnWeapons;
  23. [SerializeField] Transform ParentPlayer;
  24.  
  25. [SerializeField] Button[] buttonChoice;
  26. public bool IsClick;
  27. public GameObject PanelChoice;
  28. int ID;
  29. public static DropInventory dropInventory;
  30.  
  31.  
  32. private void Awake()
  33. {
  34. PanelForIcons = GameObject.Find("CanvasPL").transform.GetChild(0);
  35. }
  36.  
  37. private void Start()
  38. {
  39. // PanelForIcons = GameObject.Find("CanvasPL").transform.GetChild(0);
  40.  
  41.  
  42. for (int i = 0; i < Weapons.Length; i++)
  43. {
  44. Weapons[i] = Resources.Load<Weapon>(TypeWeapons[i]);
  45. }
  46. }
  47.  
  48.  
  49. void PropertyItems_Text(Text txtGm, Text txtGmTwo, int id)
  50. {
  51.  
  52.  
  53. switch (IdItems)
  54. {
  55. case 0:
  56. txtGm.text = Weapons[id].PowerDamage.ToString();
  57. txtGmTwo.text = Weapons[id].NameWeapon.ToString();
  58. break;
  59.  
  60. case 1:
  61. txtGm.text = Car[id].Hp.ToString();
  62. txtGmTwo.text = Car[id].MotorForce.ToString();
  63. print("sac");
  64. break;
  65. }
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73. void SpawnItems(int id, IdicatorWeapons weapons, Idicator_Cars idicator_Cars)
  74. {
  75. switch (IdItems)
  76. {
  77. case 0:
  78. Given_Weapon(weapons.IdWp, weapons);
  79. break;
  80. case 1:
  81. Given_KeysCar(idicator_Cars.idCar, idicator_Cars);
  82. break;
  83. }
  84. }
  85.  
  86. void SpawnDescriptions(IdicatorWeapons weapons, Idicator_Cars cars)
  87. {
  88. switch (IdItems)
  89. {
  90. case 0:
  91. Descriptions(weapons, null);
  92. break;
  93. case 1:
  94. Descriptions(null, cars);
  95. print("case 1");
  96. break;
  97. }
  98. }
  99.  
  100. public void SpawPanel(IdicatorWeapons weapons, Idicator_Cars idicator_Cars)
  101. {
  102.  
  103. if (PanelChoice == null)
  104. {
  105.  
  106. Transform ChoicePanel;
  107. if (IdItems <= 0)
  108. {
  109. ChoicePanel = Resources.Load<Transform>("Panel_ChoiceWeapon");
  110. }
  111. else
  112. {
  113. ChoicePanel = Resources.Load<Transform>("Panel_Choice_Car");
  114. }
  115. Transform spawnPanel = Instantiate(ChoicePanel, GameObject.Find("PanelForChoice").transform);
  116. PanelChoice = spawnPanel.gameObject;
  117. buttonChoice[0] = PanelChoice.transform.GetChild(0).transform.GetChild(0).GetComponent<Button>();
  118. buttonChoice[1] = PanelChoice.transform.GetChild(0).transform.GetChild(1).GetComponent<Button>();
  119.  
  120.  
  121. if (buttonChoice[0] || buttonChoice[1] != null)
  122. {
  123.  
  124. buttonChoice[0].onClick.AddListener(delegate
  125. {
  126. SpawnItems(IdItems, weapons, idicator_Cars);
  127. });
  128.  
  129.  
  130. buttonChoice[1].onClick.AddListener(delegate
  131. {
  132.  
  133.  
  134. SpawnDescriptions(weapons, idicator_Cars);
  135.  
  136. });
  137. }
  138. print("Method:SpawPanel");
  139. }
  140.  
  141. }
  142.  
  143. IEnumerator EnumeratorSpwn(IdicatorWeapons weapons, Idicator_Cars idicator_Cars)
  144. {
  145. yield return new WaitForSeconds(1f);
  146. SpawPanel(weapons, idicator_Cars);
  147.  
  148. }
  149.  
  150. public void Given_Weapon(int id, IdicatorWeapons idicator)
  151. {
  152. IsClick = true;
  153. Debug.Log(id);
  154. GameObject spawObjects = Instantiate(SpawnWeapons[id], ParentPlayer);
  155. spawObjects.transform.GetChild(0).GetComponent<Shoting>().weapon = Weapons[id];
  156.  
  157.  
  158. Destroy(idicator.button.gameObject);
  159. Destroy(PanelChoice);
  160. }
  161.  
  162. public void Given_KeysCar(int id, Idicator_Cars idicator_Cars)
  163. {
  164. IsClick = true;
  165. BoxItems.boxItems.car[id] = Car[id];
  166. Destroy(idicator_Cars.Button_Gm.gameObject);
  167. Destroy(PanelChoice);
  168.  
  169. }
  170.  
  171. public void Descriptions(IdicatorWeapons idicatorDescrp, Idicator_Cars cars)
  172. {
  173. GameObject PanelDescriptions = buttonChoice[1].transform.GetChild(0).gameObject;
  174.  
  175. if (PanelDescriptions.activeSelf)
  176. {
  177. PanelDescriptions.SetActive(false);
  178.  
  179.  
  180.  
  181. }
  182. else
  183. {
  184. PanelDescriptions.SetActive(true);
  185.  
  186. switch (IdItems)
  187. {
  188. case 0:
  189. PropertyItems_Text(GameObject.Find("UnitPropertyes").GetComponent<Text>(),
  190. GameObject.Find("UnitPropertyes (1)").GetComponent<Text>(), idicatorDescrp.IdWp);
  191. break;
  192. case 1:
  193. PropertyItems_Text(GameObject.Find("UnitPropertyes").GetComponent<Text>(),
  194. GameObject.Find("UnitPropertyes (1)").GetComponent<Text>(), cars.idCar);
  195. break;
  196. }
  197. }
  198.  
  199.  
  200.  
  201. }
  202.  
  203. public void SetActiveChoice(IdicatorWeapons weapons, Idicator_Cars idicator_Cars)
  204. {
  205.  
  206. print("Method:SetActiveChoice");
  207. if (PanelChoice != null)
  208. {
  209. Debug.Log("Work");
  210. Destroy(PanelChoice);
  211.  
  212. }
  213.  
  214.  
  215. StartCoroutine(EnumeratorSpwn(weapons, idicator_Cars));
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224. }
  225. public void SpawnInventoryDrop()
  226. {
  227.  
  228.  
  229. for (int i = 0; i <= TypeWeapons.Length - 1; i++)
  230. {
  231.  
  232. Transform Cell = Resources.Load<Transform>(TypeWeapons[i]);
  233. Transform spawn = Instantiate(Cell, PanelForIcons);
  234.  
  235. switch (IdItems)
  236. {
  237. case 0:
  238. spawn.GetComponent<IdicatorWeapons>().IdWp = i;
  239. break;
  240. case 1:
  241. spawn.GetComponent<Idicator_Cars>().idCar = i;
  242. break;
  243. }
  244.  
  245.  
  246.  
  247. }
  248.  
  249.  
  250.  
  251.  
  252.  
  253. }
  254.  
  255.  
  256. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement