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; [SerializeField] private GameObject parentForCard; private List linkList = new List(); [SerializeField] private float distX = 200; [SerializeField] private float cardScale = 0.6f; [SerializeField] private float startCardShift = 50f; private void Awake() { if (main != null && main != this) { Debug.LogWarning("2 equipmentinfo on the scene"); Destroy(this); return; } main = this; } private void Start() { CardAbout(0); } public void CardAbout(int _index) { localName.text = Inventory.main.allEquipment[_index].GetComponent().equipmentConfig.equipmentCharacteristics.name; desqription.text = Inventory.main.allEquipment[_index].GetComponent().equipmentConfig.equipmentCharacteristics.description; icon.sprite = Inventory.main.allEquipment[_index].GetComponent().equipmentConfig.equipmentCharacteristics.sprite; if (Inventory.main.EquipedOrNot(Inventory.main.lastCardNum)) AddButton.GetComponentInChildren().text = "UnEquip"; else AddButton.GetComponentInChildren().text = "Equip"; InstantiateCard(_index); } public void InstantiateCard(int _num) { for (int i = 0; i < linkList.Count; i++) { Destroy(linkList[i]); } linkList.Clear(); List _localList = new List(); for (int i = 0; i < Inventory.main.allEquipment[_num].GetComponent().equipmentConfig.equipmentCharacteristics.equipmentCards.Length; i++) { if (_localList.Contains(Inventory.main.allEquipment[_num].GetComponent().equipmentConfig.equipmentCharacteristics.equipmentCards[i]) == false) _localList.Add(Inventory.main.allEquipment[_num].GetComponent().equipmentConfig.equipmentCharacteristics.equipmentCards[i]); } float _x; if (_localList.Count % 2 == 0) _x = -(startCardShift + startCardShift * (_localList.Count / 2)); else _x = -(startCardShift * 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(cardScale, cardScale, cardScale); _x += distX; } } }