From 00e2489036c45bf4c1e6942375cba8d44eb4e5d4 Mon Sep 17 00:00:00 2001 From: yonggyun Date: Wed, 25 Jun 2025 17:13:27 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B8=EB=B2=A4=ED=86=A0=EB=A6=AC=20+=20?= =?UTF-8?q?=EB=B9=8C=EB=93=9C=EC=9A=A9=20=EC=95=84=EC=9D=B4=ED=85=9C=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20ui=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scirpts/Inventory.cs | 46 -------------- Assets/Scirpts/ItemBuild.meta | 8 +++ Assets/Scirpts/ItemBuild/Inventory.cs | 61 +++++++++++++++++++ .../Scirpts/{ => ItemBuild}/Inventory.cs.meta | 0 Assets/Scirpts/ItemBuild/ItemUI.cs | 21 +++++++ Assets/Scirpts/ItemBuild/ItemUI.cs.meta | 2 + 6 files changed, 92 insertions(+), 46 deletions(-) delete mode 100644 Assets/Scirpts/Inventory.cs create mode 100644 Assets/Scirpts/ItemBuild.meta create mode 100644 Assets/Scirpts/ItemBuild/Inventory.cs rename Assets/Scirpts/{ => ItemBuild}/Inventory.cs.meta (100%) create mode 100644 Assets/Scirpts/ItemBuild/ItemUI.cs create mode 100644 Assets/Scirpts/ItemBuild/ItemUI.cs.meta diff --git a/Assets/Scirpts/Inventory.cs b/Assets/Scirpts/Inventory.cs deleted file mode 100644 index deb9a76df..000000000 --- a/Assets/Scirpts/Inventory.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; - -namespace DDD -{ - public class Inventory : MonoBehaviour - { - Dictionary inventory; - private List unusedItems; - - void Start() - { - var task= GoogleSheetManager.LoadSo(); - var items = task.Result; - - unusedItems = new List(); - - // TODO: 데이터에서 가져오기 - inventory = new Dictionary(); - 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) - { - - } - } - } -} \ No newline at end of file diff --git a/Assets/Scirpts/ItemBuild.meta b/Assets/Scirpts/ItemBuild.meta new file mode 100644 index 000000000..8fcec191d --- /dev/null +++ b/Assets/Scirpts/ItemBuild.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9a48bb4383d2a5549ae3cb55883e22ad +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scirpts/ItemBuild/Inventory.cs b/Assets/Scirpts/ItemBuild/Inventory.cs new file mode 100644 index 000000000..177ce3a6e --- /dev/null +++ b/Assets/Scirpts/ItemBuild/Inventory.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace DDD +{ + public class Inventory : MonoBehaviour + { + public RectTransform inventoryRoot; + public ItemUI itemPrefab; + + private Dictionary inventory; + private Stack unusedItemUIs; + private Transform unusedRoot; + + private async void Start() + { + var task = GoogleSheetManager.LoadSo(); + var items = await task; + + itemPrefab.transform.SetParent(null); + itemPrefab.gameObject.SetActive(false); + + unusedItemUIs = new Stack(); + var obj = new GameObject("UnusedRoot"); + obj.SetActive(false); + unusedRoot = obj.transform; + + // TODO: 데이터에서 가져오기 + inventory = new Dictionary(); + 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()); + child.SetParent(unusedRoot); + } + + foreach (var item in inventory) + { + var usingPool = unusedItemUIs.TryPop(out var itemObject); + + if (usingPool == false) + { + itemObject = Instantiate(itemPrefab.gameObject).GetComponent(); + } + itemObject.gameObject.SetActive(true); + itemObject.transform.SetParent(inventoryRoot); + itemObject.SetUpItem(item.Value); + } + } + } +} \ No newline at end of file diff --git a/Assets/Scirpts/Inventory.cs.meta b/Assets/Scirpts/ItemBuild/Inventory.cs.meta similarity index 100% rename from Assets/Scirpts/Inventory.cs.meta rename to Assets/Scirpts/ItemBuild/Inventory.cs.meta diff --git a/Assets/Scirpts/ItemBuild/ItemUI.cs b/Assets/Scirpts/ItemBuild/ItemUI.cs new file mode 100644 index 000000000..acc2ab9bb --- /dev/null +++ b/Assets/Scirpts/ItemBuild/ItemUI.cs @@ -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; + } +} \ No newline at end of file diff --git a/Assets/Scirpts/ItemBuild/ItemUI.cs.meta b/Assets/Scirpts/ItemBuild/ItemUI.cs.meta new file mode 100644 index 000000000..f91e5c5c7 --- /dev/null +++ b/Assets/Scirpts/ItemBuild/ItemUI.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 850a1aa7f7d1eb94a894d47d98a02d8f \ No newline at end of file