[내일 배움 캠프 Unity 4기] W8D2 06.04 TIL

김용준·2024년 6월 4일
0

내일배움캠프

목록 보기
28/47

Goals

  • Apply inventory UI on framework

Inventory system on 3D Unity project

For the developer encount the framework which is not familiar, There's some period for the adaptation. The case of me is pretty same. I participated in team project and there's a framework that I've never been used. With my low knowledge, I tried to implement inventory with the basic of tutorial lecture. Attaching itemslots on the inventory, the code structure was designed like

public class UIInventory : MonoBehaviour
{
  [SerializeField] UIItemSlot[] slots;
  
  void Start()
  {
    Init()
  }
  
  void Init()
  {
    SetInventorySlot()
  }
  
  void SetInventorySlot()
  {
    slots = new UIItemSlot[27];
    for(int i=0; i<slots.Length; i++)
    {
      // 동적생성
      UIItemSlot itemSlot = Manager.UI.MakeSubItem<UIItemSlot>(gameobject.transform);
      slots[i] = itemSlot;
    }
  }
}

Previously, I tried this with the drag-and-drop method in inspector. There is a comment. When you participate the large project, there are so many errors occur at the inspector. In order to prevent that situation, we have to learn the method of controlling by script.

Previous settings

Slot prefabs were attached by developer. In that case, the object name should be tuned with the script.

Current settings

the UI_ItemSlot were instantiated by script.

profile
꿈이큰개발자지망생

0개의 댓글