mirror of
https://github.com/DerTyp7/fps-citybuild-unity.git
synced 2025-10-29 12:22:07 +01:00
Added Basic ResourceManagement
This commit is contained in:
@@ -38,7 +38,7 @@ RenderSettings:
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 705507994}
|
||||
m_IndirectSpecularColor: {r: 0.2277222, g: 0.2251251, b: 0.2237271, a: 1}
|
||||
m_IndirectSpecularColor: {r: 0.5996083, g: 0.5927744, b: 0.588867, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
@@ -382,6 +382,7 @@ Transform:
|
||||
- {fileID: 1667291200}
|
||||
- {fileID: 1238304666}
|
||||
- {fileID: 1300620966}
|
||||
- {fileID: 763358974}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 6
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
@@ -638,6 +639,119 @@ RectTransform:
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0, y: 0}
|
||||
--- !u!1 &763358969
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 763358974}
|
||||
- component: {fileID: 763358973}
|
||||
- component: {fileID: 763358972}
|
||||
- component: {fileID: 763358971}
|
||||
- component: {fileID: 763358970}
|
||||
m_Layer: 0
|
||||
m_Name: Warehouse
|
||||
m_TagString: StorageBuilding
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &763358970
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 763358969}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 8a48bc1459390b4459fbf54ad16b50f9, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
title: New Building
|
||||
description: A cool new building
|
||||
inventory: []
|
||||
inventorySpace: 0
|
||||
--- !u!65 &763358971
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 763358969}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 1, y: 1, z: 1}
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!23 &763358972
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 763358969}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_StaticShadowCaster: 0
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!33 &763358973
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 763358969}
|
||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!4 &763358974
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 763358969}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 84.6, y: 21, z: 29.60771}
|
||||
m_LocalScale: {x: 10, y: 10, z: 10}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 317073667}
|
||||
m_RootOrder: 4
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1048269303
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1156,8 +1270,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 241231c1be475704d8a3fded0c1a9d63, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
itemList:
|
||||
- {fileID: 11400000, guid: 89329e8fd5243144e83e179fb10df382, type: 2}
|
||||
storageBuildings: []
|
||||
--- !u!1001 &7029954222161724659
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9309bb620f211124297c6d9da498fca1
|
||||
NativeFormatImporter:
|
||||
guid: 67b1c241d94696c409ad579573961232
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89329e8fd5243144e83e179fb10df382
|
||||
NativeFormatImporter:
|
||||
guid: 03d0b1e434e28de4f9f37f90abf6d095
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
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
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ TagManager:
|
||||
- Building
|
||||
- Terrain
|
||||
- Blueprint
|
||||
- StorageBuilding
|
||||
layers:
|
||||
- Default
|
||||
- TransparentFX
|
||||
|
||||
Reference in New Issue
Block a user