PO/Assets/Inventory/EquipmentInfo.cs

80 lines
2.7 KiB
C#

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<GameObject> linkList = new List<GameObject>();
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<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";
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;
}
}
}