2022-01-17 17:49:27 +03:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
public class EquipmentInfo : MonoBehaviour
|
|
|
|
{
|
|
|
|
public static EquipmentInfo main;
|
|
|
|
[SerializeField] private Text localName;
|
|
|
|
[SerializeField] private Text desqription;
|
|
|
|
|
|
|
|
[SerializeField] private Image icon;
|
|
|
|
[SerializeField] private Button AddButton;
|
|
|
|
|
2022-02-01 14:34:57 +03:00
|
|
|
[SerializeField] private GameObject parentForCard;
|
|
|
|
private List<GameObject> linkList = new List<GameObject>();
|
|
|
|
|
2022-01-17 17:49:27 +03:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
if (main != null && main != this)
|
|
|
|
{
|
2022-01-20 11:44:38 +03:00
|
|
|
Debug.LogWarning("2 equipmentinfo on the scene");
|
2022-01-17 17:49:27 +03:00
|
|
|
Destroy(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
main = this;
|
|
|
|
}
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
CardAbout(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CardAbout(int _index)
|
|
|
|
{
|
|
|
|
localName.text = Inventory.main.allEquipment[_index].GetComponent<Equipment>().equipmentConfig.equipmentCharacteristics.name;
|
|
|
|
desqription.text = Inventory.main.allEquipment[_index].GetComponent<Equipment>().equipmentConfig.equipmentCharacteristics.description;
|
|
|
|
icon.sprite = Inventory.main.allEquipment[_index].GetComponent<Equipment>().equipmentConfig.equipmentCharacteristics.sprite;
|
|
|
|
if (Inventory.main.EquipedOrNot(Inventory.main.lastCardNum))
|
|
|
|
AddButton.GetComponentInChildren<Text>().text = "UnEquip";
|
|
|
|
else
|
|
|
|
AddButton.GetComponentInChildren<Text>().text = "Equip";
|
2022-02-01 14:34:57 +03:00
|
|
|
InstantiateCard(_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void InstantiateCard(int _num)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < linkList.Count; i++)
|
|
|
|
{
|
|
|
|
Destroy(linkList[i]);
|
|
|
|
}
|
|
|
|
linkList.Clear();
|
|
|
|
|
|
|
|
List<GameObject> _localList = new List<GameObject>();
|
|
|
|
for (int i = 0; i < Inventory.main.allEquipment[_num].GetComponent<Equipment>().equipmentConfig.equipmentCharacteristics.equipmentCards.Length; i++)
|
|
|
|
{
|
|
|
|
if (_localList.Contains(Inventory.main.allEquipment[_num].GetComponent<Equipment>().equipmentConfig.equipmentCharacteristics.equipmentCards[i]) == false)
|
|
|
|
_localList.Add(Inventory.main.allEquipment[_num].GetComponent<Equipment>().equipmentConfig.equipmentCharacteristics.equipmentCards[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
float _x;
|
|
|
|
|
|
|
|
if (_localList.Count % 2 == 0)
|
|
|
|
_x = -(50f + 50f * (_localList.Count / 2));
|
|
|
|
else
|
|
|
|
_x = -(50 * Mathf.Ceil(_localList.Count / 2));
|
|
|
|
|
|
|
|
print(_x);
|
|
|
|
|
|
|
|
for (int i = 0; i < _localList.Count; i++)
|
|
|
|
{
|
|
|
|
GameObject link = Instantiate(_localList[i], parentForCard.transform);
|
|
|
|
linkList.Add(link);
|
|
|
|
link.transform.localPosition = new Vector3(_x, 0, 0);
|
|
|
|
link.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
|
|
|
|
_x += 200f;
|
|
|
|
}
|
2022-01-17 17:49:27 +03:00
|
|
|
}
|
|
|
|
}
|