test mesh

This commit is contained in:
jze9
2026-04-17 02:14:56 +05:00
parent 087db550f1
commit 64293937a7
50 changed files with 2570 additions and 963 deletions

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections.Generic;
using System.IO;
/// <summary>
/// Пример конфигурации предметов
@@ -11,28 +12,43 @@ public class InventoryExampleItems : MonoBehaviour
void Awake()
{
// Создаём примеры предметов если база пустая
// Создаём примеры предметов если список пустой
if (items == null || items.Count == 0)
{
items = CreateExampleItems();
}
// Передаём в InventoryManager
var im = FindObjectOfType<InventoryManager>();
if (im != null)
{
im.itemDatabase = items;
im.RebuildItemDictionary();
if (im == null) return;
// Сразу добавляем тестовые предметы
// Объединяем с существующей базой — не заменяем!
// Так кастомные предметы (tree.asset и т.д.) из Inspector'а сохраняются.
if (im.itemDatabase == null)
im.itemDatabase = new List<ItemData>();
foreach (var item in items)
{
if (item != null && !im.itemDatabase.Exists(x => x?.id == item.id))
im.itemDatabase.Add(item);
}
im.RebuildItemDictionary();
// Тестовые предметы добавляем ТОЛЬКО если нет сохранения
// Иначе они будут перезаписаны загрузкой в Start() и появляться снова при каждом запуске
string savePath = Path.Combine(Application.persistentDataPath, "inventory_save.json");
if (!File.Exists(savePath))
{
im.AddItem("stone", 32);
im.AddItem("dirt", 16);
im.AddItem("wood", 8);
im.AddItem("apple", 5);
im.AddItem("sword", 1);
im.AddItem("pickaxe", 1);
Debug.Log("[InventoryExampleItems] Added test items");
Debug.Log("[InventoryExampleItems] No save found — added test items");
}
else
{
Debug.Log("[InventoryExampleItems] Save exists — skipping test items, load will restore inventory");
}
}