65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Inventory : MonoBehaviour
|
|
{
|
|
public static Inventory main;
|
|
public List<GameObject> allEquipment = new List<GameObject>();
|
|
public List<GameObject> playerEquipment = new List<GameObject>();
|
|
[SerializeField] public List<GameObject> localplayerEquipment = new List<GameObject>();
|
|
|
|
public Sprite imagePlug;
|
|
|
|
//0 - Hat, 1 - Gloves, 2 - Armor, 3 - Weapon, 4 - Pet, 5 - Shoes
|
|
public List<Button> playerPlace = new List<Button>();
|
|
|
|
public int lastCardNum;
|
|
|
|
private void Awake()
|
|
{
|
|
if (main != null && main != this)
|
|
{
|
|
Debug.LogWarning("2 inventory on the scene");
|
|
Destroy(this);
|
|
return;
|
|
}
|
|
main = this;
|
|
CheckData();
|
|
localplayerEquipment.AddRange(allEquipment);
|
|
}
|
|
public void CheckData()
|
|
{
|
|
playerEquipment = DataHolder.main.PlayerEquipment;
|
|
allEquipment = DataHolder.main.AllEquipment;
|
|
}
|
|
public bool EquipedOrNot(int _num)
|
|
{
|
|
for (int i = 0; i < playerEquipment.Count; i++)
|
|
{
|
|
if (playerEquipment[i].name == allEquipment[_num].name)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void WhichPlace(int _num)
|
|
{
|
|
for (int i = 0; i < playerPlace.Count; i++)
|
|
{
|
|
var _config =
|
|
allEquipment[_num].GetComponent<Equipment>().equipmentConfig.
|
|
equipmentCharacteristics;
|
|
if (_config == null) Debug.LogError("config not found!");
|
|
if (playerPlace[i].name == _config.place.ToString())
|
|
{
|
|
playerPlace[i].image.sprite = _config.sprite;
|
|
playerPlace[i].GetComponent<PlaceEquipment>().equipmentNum = lastCardNum;
|
|
}
|
|
}
|
|
}
|
|
}
|