Compare commits

...

2 Commits

Author SHA1 Message Date
NTG_Lenovo
cc0459eb33 에셋 및 메타 데이터 추가 2025-07-21 19:51:22 +09:00
NTG_Lenovo
3d54e764bc DDD-64 아이템 인벤토리 시스템 기본 구성 2025-07-21 19:51:11 +09:00
8 changed files with 177 additions and 0 deletions

View File

@ -0,0 +1,47 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &8506009925984544825
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1612822500460089190}
- component: {fileID: 5539371897028506726}
m_Layer: 0
m_Name: InventoryManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1612822500460089190
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8506009925984544825}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5539371897028506726
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8506009925984544825}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c5382d2944fd05940b84bd44b641d198, type: 3}
m_Name:
m_EditorClassIdentifier:
_persistent: 1

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 21cff8c1505cd8041a474795e35e0192
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
namespace DDD
{
public class InventoryItemData : IId
{
public string Id { get; set; }
public int Quantity { get; set; }
public InventoryItemData(string id, int quantity)
{
Id = id;
Quantity = quantity;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 55253b10460c49dcb72e484467bf8ca5
timeCreated: 1753093577

View File

@ -0,0 +1,97 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
namespace DDD
{
public class InventoryManager : Singleton<InventoryManager>, IManager
{
private Dictionary<string, ItemData> _itemDataLookup;
private Dictionary<string, InventoryItemData> _inventoryItemDatas;
public void PreInit()
{
}
public Task Init()
{
return Task.CompletedTask;
}
public void PostInit()
{
InitializeItemData();
}
private void InitializeItemData()
{
var itemDataSo = DataManager.Instance.ItemDataSo;
Debug.Assert(itemDataSo != null, "itemDataSo != null");
_itemDataLookup = itemDataSo.GetDataList()
.Where(item => !string.IsNullOrEmpty(item.Id))
.ToDictionary(item => item.Id, item => item);
_inventoryItemDatas = new Dictionary<string, InventoryItemData>(itemDataSo.GetDataCount());
}
public bool AddItem(string id, int quantity = 1)
{
if (!_itemDataLookup.ContainsKey(id))
{
Debug.LogError($"[Inventory] 등록되지 않은 아이템 ID: {id}");
return false;
}
if (_inventoryItemDatas.TryGetValue(id, out var itemData))
{
itemData.Quantity += quantity;
}
else
{
_inventoryItemDatas[id] = new InventoryItemData(id, quantity);
}
EventBus.Broadcast(new InventoryChangedEvent());
return true;
}
public bool RemoveItem(string id, int quantity = 1)
{
if (!_inventoryItemDatas.TryGetValue(id, out var itemData))
{
Debug.LogError($"[Inventory] 등록되지 않은 아이템 ID: {id}");
return false;
}
if (itemData.Quantity < quantity)
{
Debug.LogWarning($"[Inventory] 보유 수량보다 삭제하는 수량이 더 많습니다 " +
$"{id}, 보유 수량 : {itemData.Quantity}, 삭제 수량 : {quantity}");
return false;
}
itemData.Quantity -= quantity;
if (itemData.Quantity <= 0)
{
_inventoryItemDatas.Remove(id);
}
EventBus.Broadcast(new InventoryChangedEvent());
return true;
}
public IReadOnlyDictionary<string, InventoryItemData> InventoryItems => _inventoryItemDatas;
public bool TryGetItemData(string id, out ItemData itemData) => _itemDataLookup.TryGetValue(id, out itemData);
public int GetItemCount(string id) => _inventoryItemDatas.TryGetValue(id, out var itemData) ? itemData.Quantity : 0;
public ItemData GetItemDataByIdOrNull(string id)
{
_itemDataLookup.TryGetValue(id, out var itemData);
return itemData;
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c5382d2944fd05940b84bd44b641d198

View File

@ -20,4 +20,9 @@ public class InteractionEvent : IEvent
public GameObject Causer; public GameObject Causer;
public GameObject Target; public GameObject Target;
} }
public class InventoryChangedEvent : IEvent
{
}
} }

View File

@ -20,5 +20,7 @@ public List<T> GetDataList()
{ {
return Datas; return Datas;
} }
public int GetDataCount() => Datas.Count;
} }
} }