fix чать инвенторя
This commit is contained in:
@@ -78,51 +78,33 @@ public class InventoryManager : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Инициализация слотов
|
||||
// Слоты созданы editor-инструментом и назначены в Inspector
|
||||
if (slots == null || slots.Length == 0)
|
||||
{
|
||||
Debug.LogWarning("Slots not assigned! Assign them in Inspector or use InventoryUIBuilder.");
|
||||
}
|
||||
Debug.LogWarning("[InventoryManager] Slots not assigned! Run Tools > Setup Complete Scene first.");
|
||||
else
|
||||
{
|
||||
foreach (var slot in slots)
|
||||
{
|
||||
slot?.UpdateSlotUI();
|
||||
}
|
||||
}
|
||||
foreach (var slot in slots) slot?.UpdateSlotUI();
|
||||
|
||||
if (hotbarSlots != null)
|
||||
{
|
||||
foreach (var slot in hotbarSlots)
|
||||
{
|
||||
slot?.UpdateSlotUI();
|
||||
}
|
||||
}
|
||||
foreach (var slot in hotbarSlots) slot?.UpdateSlotUI();
|
||||
|
||||
// Скрыть инвентарь по умолчанию
|
||||
if (inventoryPanel != null)
|
||||
inventoryPanel.SetActive(false);
|
||||
|
||||
// Убедимся что события существуют
|
||||
if (InventoryEvents.Instance == null)
|
||||
// Подписка на ввод
|
||||
if (PlayerInput.Instance != null)
|
||||
{
|
||||
var eventsGO = new GameObject("InventoryEvents");
|
||||
eventsGO.AddComponent<InventoryEvents>();
|
||||
PlayerInput.Instance.OnToggleInventory += ToggleInventory;
|
||||
PlayerInput.Instance.OnDropPressed += DropSelectedItem;
|
||||
PlayerInput.Instance.OnHotbarSelect += SelectHotbarSlot;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[InventoryManager] PlayerInput not found. Run Tools > Setup Complete Scene first.");
|
||||
}
|
||||
|
||||
// Попробуем загрузить сохранённый инвентарь
|
||||
// Загрузить сохранённый инвентарь (слоты уже существуют)
|
||||
LoadFromFile();
|
||||
|
||||
// Ensure PlayerInput exists and subscribe to input events
|
||||
if (PlayerInput.Instance == null)
|
||||
{
|
||||
var go = new GameObject("PlayerInput");
|
||||
go.AddComponent<PlayerInput>();
|
||||
}
|
||||
|
||||
PlayerInput.Instance.OnToggleInventory += ToggleInventory;
|
||||
PlayerInput.Instance.OnDropPressed += DropSelectedItem;
|
||||
PlayerInput.Instance.OnHotbarSelect += SelectHotbarSlot;
|
||||
}
|
||||
|
||||
|
||||
@@ -135,14 +117,18 @@ public class InventoryManager : MonoBehaviour
|
||||
|
||||
if (!wasActive)
|
||||
{
|
||||
// Открытие инвентаря
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
InventoryEvents.Instance?.OnInventoryOpened?.Invoke();
|
||||
if (PlayerInput.Instance != null)
|
||||
PlayerInput.Instance.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Закрытие инвентаря
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
InventoryEvents.Instance?.OnInventoryClosed?.Invoke();
|
||||
if (PlayerInput.Instance != null)
|
||||
PlayerInput.Instance.Enabled = true;
|
||||
@@ -559,8 +545,10 @@ public class InventoryManager : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранить инвентарь в файл (Application.persistentDataPath)
|
||||
/// Сохранить инвентарь в файл (Application.persistentDataPath).
|
||||
/// Доступно через правый клик на компоненте в Inspector во время Play Mode.
|
||||
/// </summary>
|
||||
[ContextMenu("Save Inventory")]
|
||||
public void SaveToFile()
|
||||
{
|
||||
try
|
||||
@@ -577,8 +565,11 @@ public class InventoryManager : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Загрузить инвентарь из файла (если есть)
|
||||
/// Загрузить инвентарь из файла (если есть).
|
||||
/// Вызывается из InventoryUIBuilder после создания слотов.
|
||||
/// Доступно через правый клик на компоненте в Inspector во время Play Mode.
|
||||
/// </summary>
|
||||
[ContextMenu("Load Inventory")]
|
||||
public void LoadFromFile()
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user