인벤토리 기능 추가

This commit is contained in:
2026-01-27 00:34:47 +09:00
parent 658cd58e30
commit 48466bcc0f
73 changed files with 4779 additions and 228 deletions

View File

@@ -17,11 +17,8 @@ public class PlayerController : MonoBehaviour
Managers.Input.MouseAction -= OnMouseClicked;
Managers.Input.MouseAction += OnMouseClicked;
// UI 생성
// Managers.Resource.Instantiate("UI/UI_Button");
// TEMP
Managers.UI.ShowPopupUI<UI_Button>();
Managers.UI.ShowSceneUI<UI_Inven>();
}
public enum PlayerState

View File

@@ -16,7 +16,16 @@ public class ResourceManager
return null;
}
return Object.Instantiate(prefab, parent);
GameObject go = Object.Instantiate(prefab, parent);
int index = go.name.IndexOf("(Clone)");
if (index >= 0)
{
// go.name = go.name.Substring(0, index);
go.name = go.name.Remove(index);
}
return go;
}
public void Destroy(GameObject go)

View File

@@ -39,6 +39,23 @@ public class UIManager
canvas.sortingOrder = 0;
}
}
public T MakeSubItem<T>(Transform parent = null, string name = null) where T : UI_Base
{
if (string.IsNullOrEmpty(name))
{
name = typeof(T).Name;
}
GameObject go = Managers.Resource.Instantiate($"UI/SubItem/{name}");
if (parent != null)
{
go.transform.SetParent(parent);
}
return go.GetOrAddComponent<T>();
}
public T ShowSceneUI<T>(string name = null) where T : UI_Scene
{

View File

@@ -50,7 +50,7 @@ public class UI_Button : UI_Popup
GetButton((int)Buttons.PointButton).gameObject.AddUIEvent(OnButtonClicked);
GameObject go = GetImage((int)Images.ItemIcon).gameObject;
AddUIEvent(go, (PointerEventData data) => { go.transform.position = data.position; }, Define.UIEvent.Drag);
BindEvent(go, (PointerEventData data) => { go.transform.position = data.position; }, Define.UIEvent.Drag);
}
private int _score = 0;

View File

@@ -2,7 +2,7 @@ using UnityEngine;
public class UI_Popup : UI_Base
{
public virtual void Init()
public override void Init()
{
Managers.UI.SetCanvas(gameObject, true);
}

View File

@@ -0,0 +1,36 @@
using UnityEngine;
public class UI_Inven : UI_Scene
{
enum GameObjectgs
{
GridPanel,
}
void Start()
{
Init();
}
public override void Init()
{
base.Init();
Bind<GameObject>(typeof(GameObjectgs));
GameObject gridPanel = Get<GameObject>((int)GameObjectgs.GridPanel);
foreach (Transform child in gridPanel.transform)
{
Managers.Resource.Destroy(child.gameObject);
}
// 실제 인벤토리 정보를 참고해서
for (int i = 0; i < 8; i++)
{
// GameObject item = Managers.UI.MakeSubItem<UI_Inven_Item>(gridPanel.transform).gameObject;
GameObject item = Managers.UI.MakeSubItem<UI_Inven_Item>(parent: gridPanel.transform).gameObject;
UI_Inven_Item invenItem = item.GetOrAddComponent<UI_Inven_Item>();
invenItem.SetInfo($"집행검{i}번");
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3b4dc4713536bbb4190d5733bd44a302

View File

@@ -2,7 +2,7 @@ using UnityEngine;
public class UI_Scene : UI_Base
{
public virtual void Init()
public override void Init()
{
Managers.UI.SetCanvas(gameObject, false);
}

View File

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

View File

@@ -0,0 +1,33 @@
using TMPro;
using UnityEngine;
public class UI_Inven_Item : UI_Base
{
enum GameObjects
{
ItemIcon,
ItemNameText,
}
string _name;
void Start()
{
Init();
}
public override void Init()
{
Bind<GameObject>(typeof(GameObjects));
Get<GameObject>((int)GameObjects.ItemNameText).GetComponent<TextMeshProUGUI>().text = _name;
Get<GameObject>((int)GameObjects.ItemIcon).AddUIEvent((PointerEventData) => { Debug.Log($"아이템 클릭! {_name}"); });
}
public void SetInfo(string name)
{
_name = name;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9578ecba8f55ef24ca7657e44f90bdbe

View File

@@ -5,9 +5,11 @@ using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class UI_Base : MonoBehaviour
public abstract class UI_Base : MonoBehaviour
{
Dictionary<Type, UnityEngine.Object[]> _objects = new Dictionary<Type, UnityEngine.Object[]>();
public abstract void Init();
// Bind<제네릭>(인자)
protected void Bind<T>(Type type) where T : UnityEngine.Object
@@ -46,6 +48,11 @@ public class UI_Base : MonoBehaviour
return objects[idx] as T;
}
protected GameObject GetObject(int idx)
{
return Get<GameObject>(idx);
}
protected TextMeshProUGUI GetText(int idx)
{
return Get<TextMeshProUGUI>(idx);
@@ -61,7 +68,7 @@ public class UI_Base : MonoBehaviour
return Get<Image>(idx);
}
public static void AddUIEvent(GameObject go, Action<PointerEventData> action, Define.UIEvent type = Define.UIEvent.Click)
public static void BindEvent(GameObject go, Action<PointerEventData> action, Define.UIEvent type = Define.UIEvent.Click)
{
UI_EventHandler evt = Util.GetOrAddComponent<UI_EventHandler>(go);

View File

@@ -4,9 +4,13 @@ using UnityEngine.EventSystems;
public static class Extension
{
public static void AddUIEvent(this GameObject go, Action<PointerEventData> action,
Define.UIEvent type = Define.UIEvent.Click)
public static T GetOrAddComponent<T>(this GameObject go) where T : UnityEngine.Component
{
UI_Base.AddUIEvent(go, action, type);
return Util.GetOrAddComponent<T>(go);
}
public static void AddUIEvent(this GameObject go, Action<PointerEventData> action, Define.UIEvent type = Define.UIEvent.Click)
{
UI_Base.BindEvent(go, action, type);
}
}