Added Basic ResourceManagement

This commit is contained in:
DerTyp187
2021-09-30 20:44:50 +02:00
parent 4136dec646
commit 15203c52ad
22 changed files with 347 additions and 66 deletions

View File

@@ -2,13 +2,16 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New Item", menuName = "Resources/Item")]
public class Item : ScriptableObject
[System.Serializable]
public class Item
{
new public string name = "New Item";
public string name = "New Item";
public string uuid = "new_item";
public Sprite icon = null;
public bool isDefaultItem = false;
public int count = 1;
public Item(int c = 1)
{
count = c;
}
}

View File

@@ -4,33 +4,69 @@ using UnityEngine;
public class ResourceManager: MonoBehaviour
{
[SerializeField] private List<Item> itemList;
[SerializeField] private GameObject[] storageBuildings;
// Count All Resources of all storage buildings
/*
public void Remove(Item item)
private void Start()
{
itemList.Remove(item);
storageBuildings = GameObject.FindGameObjectsWithTag("StorageBuilding");
}
public void Add(Item item)
/*
private void Update()
{
itemList.Add(item);
if (Input.GetKeyDown(KeyCode.K))
{
Item wood = new WoodItem(10);
storageBuildings[0].GetComponent<StorageBuilding>().Add(wood);
}
if (Input.GetKeyDown(KeyCode.I))
{
Item stone = new StoneItem(12);
storageBuildings[0].GetComponent<StorageBuilding>().Add(stone);
}
if (Input.GetKeyDown(KeyCode.L))
{
GetAllResources();
}
}*/
public int Count(Item item)
{
int count = 0;
foreach(Item i in itemList)
public List<Item> GetAllResources()
{
List<Item> inventory = new List<Item>();
//F<>r jedes StorageBuilding
foreach(GameObject b in storageBuildings)
{
if(i == item)
List<Item> buildingInv = b.GetComponent<StorageBuilding>().Getinventory();
//Add items to already existing item +=
foreach (Item item in buildingInv)
{
foreach(Item i in inventory)
{
if(i.uuid == item.uuid)
{
i.count += item.count;
buildingInv.Remove(item);
}
}
}
//Add den Rest
foreach(Item item in buildingInv)
{
count += 1;
inventory.Add(item);
}
}
return count;
/*
Debug.Log(inventory);
Debug.Log(inventory[0].count);
Debug.Log(inventory[1].count);*/
return inventory;
}
}