Compare commits

...

6 Commits

Author SHA1 Message Date
NTG_Lenovo
e8a7e1c289 게임 이벤트 정적으로 변경 2025-07-22 12:55:04 +09:00
NTG_Lenovo
7319ee8541 Merge branch 'feature/inventory_system' of http://gitea.capers.co.kr:3000/iwnc2020/ProjectDDD into develop
# Conflicts:
#	Assets/_DDD/_Scripts/GameEvent/GameEvents.cs
2025-07-22 12:45:28 +09:00
NTG_Lenovo
ddf744ade4 메타 데이터 추가 2025-07-22 12:38:56 +09:00
NTG_Lenovo
02c675ed3f 이벤트 정적 호출 변경 및 폴더 이동 2025-07-22 12:38:48 +09:00
NTG_Lenovo
cc0459eb33 에셋 및 메타 데이터 추가 2025-07-21 19:51:22 +09:00
NTG_Lenovo
3d54e764bc DDD-64 아이템 인벤토리 시스템 기본 구성 2025-07-21 19:51:11 +09:00
12 changed files with 241 additions and 59 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,5 @@ MonoBehaviour:
- {fileID: 6471498998539637564, guid: fa2ad62c75b1549f09597e47ed5f7cfb, type: 3} - {fileID: 6471498998539637564, guid: fa2ad62c75b1549f09597e47ed5f7cfb, type: 3}
- {fileID: 7665229218737596710, guid: 71b177c2a18314c588da30429451666a, type: 3} - {fileID: 7665229218737596710, guid: 71b177c2a18314c588da30429451666a, type: 3}
- {fileID: 622422277636247943, guid: d95124918e5a4a246abb0d378b14d3fa, type: 3} - {fileID: 622422277636247943, guid: d95124918e5a4a246abb0d378b14d3fa, type: 3}
- {fileID: 5539371897028506726, guid: 21cff8c1505cd8041a474795e35e0192, type: 3}
- {fileID: 8500549904376788358, guid: d81cf4649bf54485a8b0da7a235f3817, type: 3} - {fileID: 8500549904376788358, guid: d81cf4649bf54485a8b0da7a235f3817, type: 3}

View File

@ -4,16 +4,25 @@
namespace DDD namespace DDD
{ {
// public static class GameEvents public static class GameEvents
// { {
// public static RequestTimeScaleChangeEvent RequestTimeScaleChangeEvent = new(); public static TimeScaleChangeEvent RequestTimeScaleChangeEvent = new();
// public static RequestShowGlobalMessageEvent RequestShowGlobalMessageEvent = new(); public static FadeInEvent FadeInEvent = new();
// public static InteractionEvent Interaction = new InteractionEvent(); public static FadeOutEvent FadeOutEvent = new();
// } public static OpenScreenUiEvent OpenScreenUiEvent = new();
public static CloseScreenUiEvent CloseScreenUiEvent = new();
public static OpenPopupUiEvent OpenPopupUiEvent = new();
public static ClosePopupUiEvent ClosePopupUiEvent = new();
public static ShowGlobalMessageEvent RequestShowGlobalMessageEvent = new();
public static InteractionEvent Interaction = new();
public static InventoryChangedEvent InventoryChangedEvent = new();
}
// public static class RestaurantEvents // public static class RestaurantEvents
// { // {
// // Some events... // // Some events...
// } // }
// public static class VoyageEvents // public static class VoyageEvents
// { // {
// // Some events... // // Some events...
@ -21,80 +30,51 @@ namespace DDD
public class TimeScaleChangeEvent : IEvent public class TimeScaleChangeEvent : IEvent
{ {
public readonly object Requester; public object Requester;
public readonly float NewTimeScale; public float NewTimeScale;
public TimeScaleChangeEvent(object requester, float newTimeScale)
{
Requester = requester;
NewTimeScale = newTimeScale;
}
} }
public class FadeInEvent : IEvent public class FadeInEvent : IEvent
{ {
public readonly float Duration; public float Duration;
public readonly TaskCompletionSource<bool> CompletionSource; public TaskCompletionSource<bool> CompletionSource;
public FadeInEvent(float duration)
{
Duration = duration;
CompletionSource = new TaskCompletionSource<bool>();
}
public Task WaitAsync() => CompletionSource.Task; public Task WaitAsync() => CompletionSource.Task;
} }
public class FadeOutEvent : IEvent public class FadeOutEvent : IEvent
{ {
public readonly float Duration; public float Duration;
public readonly TaskCompletionSource<bool> CompletionSource; public TaskCompletionSource<bool> CompletionSource;
public FadeOutEvent(float duration)
{
Duration = duration;
CompletionSource = new TaskCompletionSource<bool>();
}
public Task WaitAsync() => CompletionSource.Task; public Task WaitAsync() => CompletionSource.Task;
} }
public class ShowGlobalMessageEvent : IEvent public class ShowGlobalMessageEvent : IEvent
{ {
public readonly string NewMessageKey; public string NewMessageKey;
public readonly float ShowDuration; public float ShowDuration;
public readonly float FadeDuration; public float FadeDuration;
public ShowGlobalMessageEvent(string newMessageKey, float showDuration = 3f, float fadeDuration = 0.3f)
{
NewMessageKey = newMessageKey;
ShowDuration = showDuration;
FadeDuration = fadeDuration;
}
} }
public class OpenScreenUiEvent : IEvent public class OpenScreenUiEvent : IEvent
{ {
public readonly Type UiType; public Type UiType;
public OpenScreenUiEvent(Type uiType) => UiType = uiType;
} }
public class CloseScreenUiEvent : IEvent public class CloseScreenUiEvent : IEvent
{ {
public readonly Type UiType; public Type UiType;
public CloseScreenUiEvent(Type uiType) => UiType = uiType;
} }
public class OpenPopupUiEvent : IEvent public class OpenPopupUiEvent : IEvent
{ {
public readonly Type UiType; public Type UiType;
public OpenPopupUiEvent(Type uiType) => UiType = uiType;
} }
public class ClosePopupUiEvent : IEvent public class ClosePopupUiEvent : IEvent
{ {
public readonly Type UiType; public Type UiType;
public ClosePopupUiEvent(Type uiType) => UiType = uiType;
} }
public class InteractionEvent : IEvent public class InteractionEvent : IEvent
@ -102,4 +82,6 @@ public class InteractionEvent : IEvent
public GameObject Causer; public GameObject Causer;
public GameObject Target; public GameObject Target;
} }
public class InventoryChangedEvent : IEvent { }
} }

View File

@ -17,7 +17,8 @@ public class FadeSceneTransitionHandlerSo : SceneTransitionHandler
public override async Task OnBeforeSceneActivate(SceneType sceneType) public override async Task OnBeforeSceneActivate(SceneType sceneType)
{ {
var evt = new FadeOutEvent(_fadeOutDuration); var evt = GameEvents.FadeOutEvent;
evt.Duration = _fadeOutDuration;
EventBus.Broadcast(evt); EventBus.Broadcast(evt);
await evt.WaitAsync(); await evt.WaitAsync();
} }
@ -26,8 +27,9 @@ public override async Task OnAfterSceneActivate(SceneType sceneType)
{ {
float seconds = _delayBeforeFadeIn * 1000; float seconds = _delayBeforeFadeIn * 1000;
await Task.Delay((int)(seconds)); await Task.Delay((int)(seconds));
var evt = new FadeInEvent(_fadeInDuration); var evt = GameEvents.FadeInEvent;
evt.Duration = _fadeInDuration;
EventBus.Broadcast(evt); EventBus.Broadcast(evt);
await evt.WaitAsync(); await evt.WaitAsync();
} }

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

@ -78,7 +78,10 @@ private void CloseAllScreenUIs()
if (screen.IsBlockingTime) if (screen.IsBlockingTime)
{ {
EventBus.Broadcast(new TimeScaleChangeEvent(_uiPauseRequester, 1f)); var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
timeScaleChangeEvent.Requester = _uiPauseRequester;
timeScaleChangeEvent.NewTimeScale = 1f;
EventBus.Broadcast(timeScaleChangeEvent);
} }
} }
} }
@ -93,7 +96,10 @@ public void Invoke(OpenScreenUiEvent evt)
if (screen.IsBlockingTime) if (screen.IsBlockingTime)
{ {
EventBus.Broadcast(new TimeScaleChangeEvent(screen, 0f)); var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
timeScaleChangeEvent.Requester = screen;
timeScaleChangeEvent.NewTimeScale = 0f;
EventBus.Broadcast(timeScaleChangeEvent);
} }
} }
} }
@ -106,7 +112,10 @@ public void Invoke(CloseScreenUiEvent evt)
if (screen.IsBlockingTime) if (screen.IsBlockingTime)
{ {
EventBus.Broadcast(new TimeScaleChangeEvent(screen, 1f)); var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
timeScaleChangeEvent.Requester = screen;
timeScaleChangeEvent.NewTimeScale = 1f;
EventBus.Broadcast(timeScaleChangeEvent);
} }
} }
} }
@ -119,20 +128,26 @@ public void Invoke(OpenPopupUiEvent evt)
if (popup.IsBlockingTime) if (popup.IsBlockingTime)
{ {
EventBus.Broadcast(new TimeScaleChangeEvent(popup, 0f)); var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
timeScaleChangeEvent.Requester = popup;
timeScaleChangeEvent.NewTimeScale = 0f;
EventBus.Broadcast(timeScaleChangeEvent);
} }
} }
} }
public void Invoke(ClosePopupUiEvent evt) public void Invoke(ClosePopupUiEvent evt)
{ {
if (_screenUIs.TryGetValue(evt.UiType, out var popUp)) if (_screenUIs.TryGetValue(evt.UiType, out var popup))
{ {
popUp.Close(); popup.Close();
if (popUp.IsBlockingTime) if (popup.IsBlockingTime)
{ {
EventBus.Broadcast(new TimeScaleChangeEvent(popUp, 1f)); var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
timeScaleChangeEvent.Requester = popup;
timeScaleChangeEvent.NewTimeScale = 1f;
EventBus.Broadcast(timeScaleChangeEvent);
} }
} }
} }

View File

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