[Unity] 인벤토리 만들기
UI_Inven
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UI_Inven : UI_Scene
{
enum GameObjects
{
GridPanel
}
void Start()
{
init();
}
public override void init()
{
base.init();
Bind<GameObject>(typeof(GameObjects));
GameObject gridPanel = Get<GameObject>((int)GameObjects.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;
UI_Inven_Item invenItem = item.GetOrAddComponent<UI_Inven_Item>();
invenItem.SetInfo($"집행검 {i}번");
}
}
}
UI_Inven_Item
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
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<Text>().text = _name;
Get<GameObject>((int)GameObjects.ItemIcon).BindEvent((PointerEventData) => { Debug.Log($"아이템 클릭! {_name}"); });
}
public void SetInfo(string name)
{
_name = name;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UI_Inven : UI_Scene
{
enum GameObjects
{
GridPanel
}
void Start()
{
init();
}
public override void init()
{
base.init();
Bind<GameObject>(typeof(GameObjects));
GameObject gridPanel = Get<GameObject>((int)GameObjects.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;
UI_Inven_Item invenItem = item.GetOrAddComponent<UI_Inven_Item>();
invenItem.SetInfo($"집행검 {i}번");
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
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<Text>().text = _name;
Get<GameObject>((int)GameObjects.ItemIcon).BindEvent((PointerEventData) => { Debug.Log($"아이템 클릭! {_name}"); });
}
public void SetInfo(string name)
{
_name = name;
}
}
UI_Base를 상속받아 사용하면서 override 된 init()을 사용한다.
기존 UI_Base에는 init()함수가 없었기 때문에 UI_Base 클래스를 추상 클래스로 변경하고 abstract init() 함수를 추가했다.
Author And Source
이 문제에 관하여([Unity] 인벤토리 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@kjhdx/Unity-인벤토리-만들기저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)