인벤토리처럼 하나의 프리팹안에 다른 프리팹들이 들어가있을때 어떻게 관리를 해야하는가에 대한 의문
각각의 프리팹에 대응하는 스크립트를 만들어준다.
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}번");
}
}
}
abstract 키워드를 사용해 줌으로써 UI_Inven_Item 에서도 Init() 함수를 사용할 수 있게 됬다.
abstract 키워드는 선언만 해주고 구현은 상속받은데서 하면 된다.