mirror of
https://github.com/DerTyp7/fps-citybuild-unity.git
synced 2025-10-30 20:47:08 +01:00
Added Basic ResourceManagement
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 232c60ba7df6f074d9c92fa97215e412, type: 3}
|
||||
m_Name: Stone
|
||||
m_EditorClassIdentifier:
|
||||
name: New Item
|
||||
uuid: new_item
|
||||
icon: {fileID: 0}
|
||||
isDefaultItem: 0
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9309bb620f211124297c6d9da498fca1
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Scripts/Resources/Items/StoneItem.cs
Normal file
13
Assets/Scripts/Resources/Items/StoneItem.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class StoneItem : Item
|
||||
{
|
||||
public StoneItem(int c = 1)
|
||||
{
|
||||
count = c;
|
||||
name = "Stone";
|
||||
uuid = "item_stone";
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Resources/Items/StoneItem.cs.meta
Normal file
11
Assets/Scripts/Resources/Items/StoneItem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 437c0f4d48ae7a441beeaf0c3b7376a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,17 +0,0 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 232c60ba7df6f074d9c92fa97215e412, type: 3}
|
||||
m_Name: Wood
|
||||
m_EditorClassIdentifier:
|
||||
name: Wood
|
||||
icon: {fileID: 10915, guid: 0000000000000000f000000000000000, type: 0}
|
||||
isDefaultItem: 0
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89329e8fd5243144e83e179fb10df382
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Scripts/Resources/Items/WoodItem.cs
Normal file
13
Assets/Scripts/Resources/Items/WoodItem.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WoodItem : Item
|
||||
{
|
||||
public WoodItem(int c = 1)
|
||||
{
|
||||
count = c;
|
||||
name = "Wood";
|
||||
uuid = "item_wood";
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Resources/Items/WoodItem.cs.meta
Normal file
11
Assets/Scripts/Resources/Items/WoodItem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e095dfc35783fe418bcfddbdf69924f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user