mirror of
https://github.com/DerTyp7/fps-citybuild-unity.git
synced 2025-10-29 20:22:08 +01:00
Added Basic ResourceManagement
This commit is contained in:
8
Assets/Scripts/Building/Buildings.meta
Normal file
8
Assets/Scripts/Building/Buildings.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67b1c241d94696c409ad579573961232
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Building/Buildings/Warehouse.meta
Normal file
8
Assets/Scripts/Building/Buildings/Warehouse.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03d0b1e434e28de4f9f37f90abf6d095
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WarehouseBuilding : StorageBuilding
|
||||
{
|
||||
|
||||
private void Start()
|
||||
{
|
||||
inventorySpace = 500;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a48bc1459390b4459fbf54ad16b50f9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -4,5 +4,96 @@ using UnityEngine;
|
||||
|
||||
public class StorageBuilding : Building
|
||||
{
|
||||
|
||||
[SerializeField] private List<Item> inventory = new List<Item>();
|
||||
public int inventorySpace;
|
||||
|
||||
|
||||
public void Add(Item item)
|
||||
{
|
||||
if(GetFreeSpace() >= item.count)
|
||||
{
|
||||
bool added = false;
|
||||
//Check if the Item can get stacked
|
||||
foreach (Item i in inventory)
|
||||
{
|
||||
if (i.uuid == item.uuid)
|
||||
{
|
||||
i.count += item.count;
|
||||
added = true;
|
||||
return;
|
||||
}
|
||||
added = false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
//If foreach does not work just ADD (List is empty)
|
||||
if (!added)
|
||||
{
|
||||
inventory.Add(item);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Inventory Full");
|
||||
}
|
||||
|
||||
//TODO mach wenn nicht ganz voll, dass dann so viele items added werden wie platz ist
|
||||
//Sonst wird bei 20 Holz KOMPLETT nein gesagt weil/obowhl 19 Space noch da ist
|
||||
}
|
||||
|
||||
public void Remove(Item item)
|
||||
{
|
||||
//Check if the Item can get stacked
|
||||
foreach (Item i in inventory)
|
||||
{
|
||||
if (i.uuid == item.uuid)
|
||||
{
|
||||
if(i.count > item.count)
|
||||
{
|
||||
i.count -= item.count;
|
||||
}else if(i.count <= item.count)
|
||||
{
|
||||
//!!!Muss eventuell sp<73>ter anders gehandelt werden!!!
|
||||
inventory.Remove(i); //Wenn du mehr entfernst als im Inventar ist, dann wird das Item einfach komplett removed
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int GetCountOfItem(Item item)
|
||||
{
|
||||
int count = 0;
|
||||
foreach(Item i in inventory)
|
||||
{
|
||||
if(i.uuid == item.uuid)
|
||||
{
|
||||
count += i.count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
public int GetUsedSpace()
|
||||
{
|
||||
int usedSpace = 0;
|
||||
|
||||
foreach(Item item in inventory)
|
||||
{
|
||||
usedSpace += item.count;
|
||||
}
|
||||
|
||||
return usedSpace;
|
||||
}
|
||||
|
||||
public int GetFreeSpace()
|
||||
{
|
||||
return inventorySpace - GetUsedSpace();
|
||||
}
|
||||
public List<Item> Getinventory()
|
||||
{
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user