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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
namespace InventorySystem
{
    public class InventorySystemFactory : MonoBehaviour
    {
        [Header("매니저 프리펩들")]
        [SerializeField] private GameObject itemListManagerPrefab;
        [SerializeField] private GameObject inventoryGridManagerPrefab;
 
        [Header("슬롯과 아이템 프리펩들")]
        [SerializeField] private GameObject slotSectorPrefab;
        [SerializeField] private GameObject itemPrefab;
        [SerializeField] private GameObject fieldItemPrefab; // 필드 아이템 프리펩
 
 
        [Header("동적 생성 아이템의 부모 트랜스폼")]
        [SerializeField] private Transform dragParent;
 
        [Header("아이템 데이터베이스")]
        [SerializeField] private GameObject loadItemDatabaseObj; // LoadItemDatabase 컴포넌트가 있는 오브젝트
 
        [Header("인벤토리 그리드")]
        [SerializeField] 
        private GameObject inventoryGridObj; // InventoryGrid 오브젝트
 
        private IItemListManager itemListManager;
        private IInventoryGridManager inventoryGridManager;
        private IItemDatabase itemDatabase;
        private IInventoryGrid inventoryGrid;
 
 
        private void Awake()
        {
            InitializeDatabase();
            SetupInventoryGrid();
            CreateManagers();
            InitializeStartingItems();
 
        }
 
        /// <summary>
        /// 아이템 데이터베이스를 로드하고 초기화
        /// </summary>
        private void InitializeDatabase()
        {
            itemDatabase = loadItemDatabaseObj.GetComponent<IItemDatabase>();
            if (itemDatabase == null)
            {
                Debug.LogError("LoadItemDatabase component is not implementing IItemDatabase.");
            }
        }
 
        /// <summary>
        /// 아이템 리스트 매니저와 인벤토리 그리드 매니저를 생성하고 초기화
        /// </summary>
        private void CreateManagers()
        {
            // Use the assigned object or instantiate from prefab
            if (itemListManagerPrefab != null)
            {
                var itemListManagerObj = itemListManagerPrefab;
                if (itemListManagerObj.GetComponent<IItemListManager>() != null)
                {
                    itemListManager = itemListManagerObj.GetComponent<IItemListManager>();
                }
                else
                {
                    Debug.LogError("ItemListManager component is not found on the prefab.");
                }
            }
 
            if (inventoryGridManagerPrefab != null)
            {
                var inventoryGridManagerObj = inventoryGridManagerPrefab;
                if (inventoryGridManagerObj.GetComponent<IInventoryGridManager>() != null)
                {
                    inventoryGridManager = inventoryGridManagerObj.GetComponent<IInventoryGridManager>();
                }
                else
                {
                    Debug.LogError("InventoryGridManager component is not found on the prefab.");
                }
            }
 
            // Inject dependencies
            if (itemListManager is ItemListManager itemListManagerComp && inventoryGridManager is InventoryGridManager inventoryGridManagerComp)
            {
                itemListManagerComp.Setup(inventoryGridManager, itemDatabase);
                inventoryGridManagerComp.Setup(itemListManager, itemDatabase, inventoryGrid);
            }
        }
 
        /// <summary>
        /// 인벤토리 그리드 컴포넌트를 설정
        /// </summary>
        private void SetupInventoryGrid()
        {
            if (inventoryGridObj != null)
            {
                inventoryGrid = inventoryGridObj.GetComponent<IInventoryGrid>();
 
                if (inventoryGrid is InventoryGrid grid)
                {
                    grid.Setup(inventoryGridManager);
                }
                else
                {
                    Debug.LogError("InventoryGrid component is not found on the prefab.");
                }
            }
            else
            {
                Debug.LogError("InventoryGrid is not assigned.");
            }
        }
 
        /// <summary>
        /// 슬롯 섹터를 동적으로 생성하고 의존성을 주입
        /// </summary>
        public SlotSector CreateSlotSector(GameObject slotParent, int quadNum)
        {
            GameObject sectorObject = Instantiate(slotSectorPrefab);
            sectorObject.transform.SetParent(slotParent.transform, false);
 
            SlotSector sector = sectorObject.GetComponent<SlotSector>();
            if (sector == null)
            {
                Debug.LogError("SlotSector component is not found on the prefab.");
                return null;
            }
            sector.Setup(slotParent, quadNum, inventoryGridManager, itemListManager);
 
            return sector;
        }
 
        /// <summary>
        /// 아이템을 동적으로 생성하고 의존성을 주입
        /// </summary>
        public GameObject CreateItem(InventoryItemClass itemData)
        {
            GameObject itemObj = Instantiate(itemPrefab);
            itemObj.transform.SetParent(dragParent, false);
 
            InventoryItem itemComponent = itemObj.GetComponent<InventoryItem>();
            if (itemComponent == null)
            {
                Debug.LogError("InventoryItem component is not found on the prefab.");
                return null;
            }
 
            float slotSize = inventoryGrid.GetSlotSize();
            itemComponent.Setup(itemData, slotSize, dragParent);
 
            return itemObj;
        }
        
        /// <summary>
        /// 필드 아이템을 동적으로 생성하고 의존성을 주입
        /// </summary>
        public GameObject CreateFieldItem(int itemID, Vector3 position)
        {
            GameObject fieldItemObj = Instantiate(fieldItemPrefab, position, Quaternion.identity);
 
            FieldItem fieldItemComponent = fieldItemObj.GetComponent<FieldItem>();
            if (fieldItemComponent == null)
            {
                Debug.LogError("FieldItem component is not found on the prefab.");
                return null;
            }
 
            fieldItemComponent.InjectDependencies(itemListManager, itemDatabase);
            fieldItemComponent.SetItemID(itemID); // 아이템 ID 설정
 
            return fieldItemObj;
        }
        
        /// <summary>
        /// 시작 아이템 생성
        /// </summary>
        private void InitializeStartingItems()
        {
            if (itemListManager is ItemListManager itemListManagerComp)
            {
                itemListManagerComp.InitializeStartingItems();
            }
        }
    }
}
cs

이게 내 코드인데 GPT는 자꾸 FIND 쓰라는데

FIND 함수는 막상 자원 많이 먹어서 권장 안되지 않나?

그래서 또 Find 함수 넣으면 파인드 넣었다고 자원 많이 먹는다고 화냄.

내 코드 리뷰 부탁해서 수정할 부분 수정하는데

난 GPT 얘를 이해를 못하겠음. 

계속 도돌이표임.