인벤토리 + 빌드용 아이템 리스트 ui 추가

This commit is contained in:
yonggyun 2025-06-25 17:13:27 +09:00
parent 2c00c795f6
commit 00e2489036
6 changed files with 92 additions and 46 deletions

View File

@ -1,46 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
namespace DDD
{
public class Inventory : MonoBehaviour
{
Dictionary<string, Item> inventory;
private List<RectTransform> unusedItems;
void Start()
{
var task= GoogleSheetManager.LoadSo<ItemSo>();
var items = task.Result;
unusedItems = new List<RectTransform>();
// TODO: 데이터에서 가져오기
inventory = new Dictionary<string, Item>();
inventory["0"] = items.ItemList[0];
inventory["1"] = items.ItemList[1];
inventory["2"] = items.ItemList[2];
UpdateItemList();
}
public void UpdateItemList()
{
RectTransform inventoryRoot;
RectTransform itemPrefab;
var counts = inventoryRoot.childCount;
for (int i = 0; i < counts; ++i)
{
var child = inventoryRoot.GetChild(0);
unusedItems.Add(child as RectTransform);
child.SetParent(null);
child.gameObject.SetActive(false);
}
foreach (var item in inventory)
{
}
}
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9a48bb4383d2a5549ae3cb55883e22ad
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,61 @@
using System.Collections.Generic;
using UnityEngine;
namespace DDD
{
public class Inventory : MonoBehaviour
{
public RectTransform inventoryRoot;
public ItemUI itemPrefab;
private Dictionary<string, Item> inventory;
private Stack<ItemUI> unusedItemUIs;
private Transform unusedRoot;
private async void Start()
{
var task = GoogleSheetManager.LoadSo<ItemSo>();
var items = await task;
itemPrefab.transform.SetParent(null);
itemPrefab.gameObject.SetActive(false);
unusedItemUIs = new Stack<ItemUI>();
var obj = new GameObject("UnusedRoot");
obj.SetActive(false);
unusedRoot = obj.transform;
// TODO: 데이터에서 가져오기
inventory = new Dictionary<string, Item>();
inventory["0"] = items.ItemList[0];
inventory["1"] = items.ItemList[1];
inventory["2"] = items.ItemList[2];
UpdateItemList();
}
public void UpdateItemList()
{
var counts = inventoryRoot.childCount;
for (int i = 0; i < counts; ++i)
{
var child = inventoryRoot.GetChild(0);
unusedItemUIs.Push(child.GetComponent<ItemUI>());
child.SetParent(unusedRoot);
}
foreach (var item in inventory)
{
var usingPool = unusedItemUIs.TryPop(out var itemObject);
if (usingPool == false)
{
itemObject = Instantiate(itemPrefab.gameObject).GetComponent<ItemUI>();
}
itemObject.gameObject.SetActive(true);
itemObject.transform.SetParent(inventoryRoot);
itemObject.SetUpItem(item.Value);
}
}
}
}

View File

@ -0,0 +1,21 @@
using DDD;
using TMPro;
using UnityEngine;
public class ItemUI : MonoBehaviour
{
public TextMeshProUGUI nameText;
private Item _item;
public void SetUpItem(Item item)
{
_item = item;
UpdateItem();
}
private void UpdateItem()
{
nameText.text = _item.Name;
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 850a1aa7f7d1eb94a894d47d98a02d8f