-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventoryClass.cpp
More file actions
53 lines (43 loc) · 1.1 KB
/
InventoryClass.cpp
File metadata and controls
53 lines (43 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Fill out your copyright notice in the Description page of Project Settings.
#include "InventoryClass.h"
UInventoryClass::UInventoryClass()
{
MaxInventorySize = 5;
Inventory.Init(nullptr, MaxInventorySize);
}
// Item을 Inventory에 넣음
bool UInventoryClass::AddItem(AActor* Item, int32 CurrentInventorySlot)
{
// 배열을 돌며 빈공간을 찾음
for (int32 i=0; i <MaxInventorySize; i++)
{
// 빈공간이 있는 경우 아이템을 넣고 true를 리턴
if (!Inventory[i])
{
Inventory[i] = Item;
// 현재 선택된 Inventory Slot이 아니라면 게임에서 숨기기
if(i != CurrentInventorySlot)
{
Item->SetActorHiddenInGame(true);
}
return true;
}
}
// 빈공간이 없는 경우 false;
return false;
}
bool UInventoryClass::RemoveItem(AActor* Item)
{
// 배열을 돌며 item을 찾음
for(int32 i = 0; i < MaxInventorySize; i++)
{
// inventory에 Item이 있는 경우 nullptr로 대체 후 true 리턴
if(Inventory[i] == Item)
{
Inventory[i] = nullptr;
return true;
}
}
// 아이템이 inventory에 없으므로 false 리턴
return false;
}