2026-06-01 씬전환시 무기 사라지는 현상 수정

This commit is contained in:
2026-06-01 13:06:31 +09:00
parent 964383c59c
commit 11a6a4f983
7 changed files with 67 additions and 13 deletions

View File

@@ -13,7 +13,7 @@
//
// _slots는 데이터가 아니라 생성한 화면 오브젝트 캐시일 뿐 (재사용 풀).
// ============================================================================
public class WeaponInventory : MonoBehaviour
public class WeaponInventory : MonoBehaviour, ISceneInitializable
{
[SerializeField] private PlayerWeaponInventory _wInvenSource; // 비워두면 런타임에 자동 탐색
[SerializeField] private Transform _slotRoot; // 슬롯이 생성될 부모
@@ -33,6 +33,7 @@ private void Start()
Refresh();
}
private void OnDestroy()
{
if (_wInvenSource != null)
@@ -40,6 +41,17 @@ private void OnDestroy()
}
public void OnSceneLoaded()
{
if (_wInvenSource == null)
_wInvenSource = FindFirstObjectByType<PlayerWeaponInventory>();
if (_wInvenSource != null)
_wInvenSource.OnInventoryChanged += Refresh;
Refresh();
}
// 인벤토리 상태를 화면에 반영. 슬롯 개수를 무기 수에 맞추고 내용/하이라이트 갱신.
private void Refresh()
{
@@ -61,4 +73,5 @@ private void Refresh()
_slots[i].SetSelected(i == _wInvenSource.CurrentIndex);
}
}
}