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.UI;
- using UnityEngine.Events;
- using UnityEngine.EventSystems;
- public class DropInventory : MonoBehaviour
- {
- [Header("Отвечает за тип предметов ")]
- [SerializeField]
- int IdItems;
- public Transform PanelForIcons;
- public Weapon[] Weapons;
- public KeysCar[] Car;
- [SerializeField] string[] TypeWeapons;
- [SerializeField] GameObject[] SpawnWeapons;
- [SerializeField] Transform ParentPlayer;
- [SerializeField] Button[] buttonChoice;
- public bool IsClick;
- public GameObject PanelChoice;
- int ID;
- public static DropInventory dropInventory;
- private void Awake()
- {
- PanelForIcons = GameObject.Find("CanvasPL").transform.GetChild(0);
- }
- private void Start()
- {
- // PanelForIcons = GameObject.Find("CanvasPL").transform.GetChild(0);
- for (int i = 0; i < Weapons.Length; i++)
- {
- Weapons[i] = Resources.Load<Weapon>(TypeWeapons[i]);
- }
- }
- void PropertyItems_Text(Text txtGm, Text txtGmTwo, int id)
- {
- switch (IdItems)
- {
- case 0:
- txtGm.text = Weapons[id].PowerDamage.ToString();
- txtGmTwo.text = Weapons[id].NameWeapon.ToString();
- break;
- case 1:
- txtGm.text = Car[id].Hp.ToString();
- txtGmTwo.text = Car[id].MotorForce.ToString();
- print("sac");
- break;
- }
- }
- void SpawnItems(int id, IdicatorWeapons weapons, Idicator_Cars idicator_Cars)
- {
- switch (IdItems)
- {
- case 0:
- Given_Weapon(weapons.IdWp, weapons);
- break;
- case 1:
- Given_KeysCar(idicator_Cars.idCar, idicator_Cars);
- break;
- }
- }
- void SpawnDescriptions(IdicatorWeapons weapons, Idicator_Cars cars)
- {
- switch (IdItems)
- {
- case 0:
- Descriptions(weapons, null);
- break;
- case 1:
- Descriptions(null, cars);
- print("case 1");
- break;
- }
- }
- public void SpawPanel(IdicatorWeapons weapons, Idicator_Cars idicator_Cars)
- {
- if (PanelChoice == null)
- {
- Transform ChoicePanel;
- if (IdItems <= 0)
- {
- ChoicePanel = Resources.Load<Transform>("Panel_ChoiceWeapon");
- }
- else
- {
- ChoicePanel = Resources.Load<Transform>("Panel_Choice_Car");
- }
- Transform spawnPanel = Instantiate(ChoicePanel, GameObject.Find("PanelForChoice").transform);
- PanelChoice = spawnPanel.gameObject;
- buttonChoice[0] = PanelChoice.transform.GetChild(0).transform.GetChild(0).GetComponent<Button>();
- buttonChoice[1] = PanelChoice.transform.GetChild(0).transform.GetChild(1).GetComponent<Button>();
- if (buttonChoice[0] || buttonChoice[1] != null)
- {
- buttonChoice[0].onClick.AddListener(delegate
- {
- SpawnItems(IdItems, weapons, idicator_Cars);
- });
- buttonChoice[1].onClick.AddListener(delegate
- {
- SpawnDescriptions(weapons, idicator_Cars);
- });
- }
- print("Method:SpawPanel");
- }
- }
- IEnumerator EnumeratorSpwn(IdicatorWeapons weapons, Idicator_Cars idicator_Cars)
- {
- yield return new WaitForSeconds(1f);
- SpawPanel(weapons, idicator_Cars);
- }
- public void Given_Weapon(int id, IdicatorWeapons idicator)
- {
- IsClick = true;
- Debug.Log(id);
- GameObject spawObjects = Instantiate(SpawnWeapons[id], ParentPlayer);
- spawObjects.transform.GetChild(0).GetComponent<Shoting>().weapon = Weapons[id];
- Destroy(idicator.button.gameObject);
- Destroy(PanelChoice);
- }
- public void Given_KeysCar(int id, Idicator_Cars idicator_Cars)
- {
- IsClick = true;
- BoxItems.boxItems.car[id] = Car[id];
- Destroy(idicator_Cars.Button_Gm.gameObject);
- Destroy(PanelChoice);
- }
- public void Descriptions(IdicatorWeapons idicatorDescrp, Idicator_Cars cars)
- {
- GameObject PanelDescriptions = buttonChoice[1].transform.GetChild(0).gameObject;
- if (PanelDescriptions.activeSelf)
- {
- PanelDescriptions.SetActive(false);
- }
- else
- {
- PanelDescriptions.SetActive(true);
- switch (IdItems)
- {
- case 0:
- PropertyItems_Text(GameObject.Find("UnitPropertyes").GetComponent<Text>(),
- GameObject.Find("UnitPropertyes (1)").GetComponent<Text>(), idicatorDescrp.IdWp);
- break;
- case 1:
- PropertyItems_Text(GameObject.Find("UnitPropertyes").GetComponent<Text>(),
- GameObject.Find("UnitPropertyes (1)").GetComponent<Text>(), cars.idCar);
- break;
- }
- }
- }
- public void SetActiveChoice(IdicatorWeapons weapons, Idicator_Cars idicator_Cars)
- {
- print("Method:SetActiveChoice");
- if (PanelChoice != null)
- {
- Debug.Log("Work");
- Destroy(PanelChoice);
- }
- StartCoroutine(EnumeratorSpwn(weapons, idicator_Cars));
- }
- public void SpawnInventoryDrop()
- {
- for (int i = 0; i <= TypeWeapons.Length - 1; i++)
- {
- Transform Cell = Resources.Load<Transform>(TypeWeapons[i]);
- Transform spawn = Instantiate(Cell, PanelForIcons);
- switch (IdItems)
- {
- case 0:
- spawn.GetComponent<IdicatorWeapons>().IdWp = i;
- break;
- case 1:
- spawn.GetComponent<Idicator_Cars>().idCar = i;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement