CapersProject/Assets/02.Scripts/Item/ItemManager.cs
Nam Tae Gun 87aa509cfc #7, #8 타이쿤 손님 테이블 상호작용 및 손님 Ai 추가
+ ItemTable excel, json, so 수정
+ 손님 추가 -> 빈 자리 찾기 -> 음료 주문 -> 퇴장 구현
+ 일부 BehaviorTree Action 변경
2024-06-19 03:16:19 +09:00

87 lines
3.3 KiB
C#

using System.Collections.Generic;
using BlueWater.Audios;
using BlueWater.Uis;
using Sirenix.OdinInspector;
using UnityEngine;
namespace BlueWater.Items
{
public class ItemManager : Singleton<ItemManager>
{
[SerializeField, Required]
private GameObject _dropItemControllerPrefab;
[SerializeField, Required]
private ItemDataSo _itemDataSo;
public Dictionary<int, ItemData> ItemDictionary { get; private set; }
[SerializeField, Required]
private ItemDropTableSo _itemDropTableSo;
public Dictionary<int, ItemDropTable> ItemDropTableDictionary { get; private set; }
protected override void OnAwake()
{
base.OnAwake();
Initialize();
}
private void Initialize()
{
ItemDictionary = new Dictionary<int, ItemData>(_itemDataSo.ItemDataList.Count);
foreach (var element in _itemDataSo.ItemDataList)
{
ItemDictionary.TryAdd(element.Idx, element);
}
ItemDropTableDictionary = new Dictionary<int, ItemDropTable>(_itemDropTableSo.ItemDropTableList.Count);
foreach (var element in _itemDropTableSo.ItemDropTableList)
{
ItemDropTableDictionary.TryAdd(element.Idx, element);
}
}
public void ItemDrop(int idx, Vector3 dropPosition)
{
var itemDropTable = ItemDropTableDictionary[idx];
var droppedItemList = itemDropTable.GetDroppedItemList();
foreach (var element in droppedItemList)
{
var instantiateItem = Instantiate(_dropItemControllerPrefab, dropPosition, Quaternion.identity);
instantiateItem.GetComponent<DropItemController>().Initialize(element);
}
}
public void ItemDropRandomPosition(int idx, Vector3 dropPosition)
{
var itemDropTable = ItemDropTableDictionary[idx];
var droppedItemList = itemDropTable.GetDroppedItemList();
foreach (var element in droppedItemList)
{
var newDropPositionX = Random.Range(dropPosition.x - 1f, dropPosition.x + 1f);
var newDropPositionZ = Random.Range(dropPosition.z - 1f, dropPosition.z + 1f);
var newDropPosition = new Vector3(newDropPositionX, dropPosition.y, newDropPositionZ);
var instantiateItem = Instantiate(_dropItemControllerPrefab, newDropPosition, Quaternion.identity);
instantiateItem.GetComponent<DropItemController>().Initialize(element);
instantiateItem.GetComponent<Rigidbody>().AddForce(Vector3.up * 20f, ForceMode.Impulse);
}
}
public void Acquire(ItemSlot itemSlot)
{
AudioManager.Instance.PlaySfx("GetItem");
DataManager.Instance.CombatInventory.AddItem(itemSlot);
CombatUiManager.Instance.ItemLootUi.ShowLootInfoUi(ItemDictionary[itemSlot.Idx], itemSlot.Count);
}
public ItemData GetItemDataByIdx(int idx)
{
if (ItemDictionary.TryGetValue(idx, out var itemData)) return itemData;
Debug.LogError($"{idx}와 일치하는 아이템이 없습니다.");
return null;
}
}
}