Merge branch 'feature/inventory_system' of http://gitea.capers.co.kr:3000/iwnc2020/ProjectDDD into develop

# Conflicts:
#	Assets/_DDD/_Scripts/GameEvent/GameEvents.cs
This commit is contained in:
NTG_Lenovo 2025-07-22 12:45:28 +09:00
commit 7319ee8541
10 changed files with 188 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

@ -20,4 +20,6 @@ MonoBehaviour:
- {fileID: 6471498998539637564, guid: fa2ad62c75b1549f09597e47ed5f7cfb, type: 3}
- {fileID: 7665229218737596710, guid: 71b177c2a18314c588da30429451666a, type: 3}
- {fileID: 622422277636247943, guid: d95124918e5a4a246abb0d378b14d3fa, type: 3}
- {fileID: 5136368050551183548, guid: 0aa6654feb91ef040b8b99d4f64688fc, type: 3}
- {fileID: 5539371897028506726, guid: 21cff8c1505cd8041a474795e35e0192, type: 3}
- {fileID: 8500549904376788358, guid: d81cf4649bf54485a8b0da7a235f3817, type: 3}

View File

@ -57,6 +57,8 @@ public FadeOutEvent(float duration)
}
public Task WaitAsync() => CompletionSource.Task;
public static InventoryChangedEvent InventoryChangedEvent = new();
public static InteractionEvent Interaction = new();
}
public class ShowGlobalMessageEvent : IEvent
@ -102,4 +104,6 @@ public class InteractionEvent : IEvent
public GameObject Causer;
public GameObject Target;
}
public class InventoryChangedEvent : IEvent { }
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 46b89f8970a04e14b97419aeb4acb6c4
folderAsset: yes
DefaultImporter:
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,99 @@
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);
}
InventoryChangedEvent evt = GameEvents.InventoryChangedEvent;
EventBus.Broadcast(evt);
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);
}
InventoryChangedEvent evt = GameEvents.InventoryChangedEvent;
EventBus.Broadcast(evt);
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,5 +20,7 @@ public List<T> GetDataList()
{
return Datas;
}
public int GetDataCount() => Datas.Count;
}
}