This commit is contained in:
unknown
2026-04-16 18:19:23 +05:00
parent 6c3f72385e
commit 087db550f1
43 changed files with 1676 additions and 58 deletions

View File

@@ -112,7 +112,7 @@ public class ItemBuilderTool : EditorWindow
item.description = description;
item.type = itemType;
item.modelPrefab = modelPrefab;
item.icon = icon != null ? icon : CreatePlaceholderIcon();
item.icon = icon ?? CreatePlaceholderIcon();
item.maxStack = maxStack;
item.value = value;
item.weight = weight;
@@ -155,6 +155,14 @@ public class ItemBuilderTool : EditorWindow
var worldItem = itemGO.AddComponent<WorldItem>();
worldItem.interactRange = interactRange;
// Автоматически создаём/находим ItemData и назначаем
var data = EnsureItemData();
if (data != null)
{
worldItem.itemData = data;
AddToInventoryDatabase(data);
}
// Trigger-коллайдер для OverlapSphere (не для авто-pickup!)
var col = itemGO.AddComponent<SphereCollider>();
col.radius = 0.5f;
@@ -196,6 +204,13 @@ public class ItemBuilderTool : EditorWindow
var worldItem = prefabGO.AddComponent<WorldItem>();
worldItem.interactRange = interactRange;
var data = EnsureItemData();
if (data != null)
{
worldItem.itemData = data;
AddToInventoryDatabase(data);
}
var col = prefabGO.AddComponent<SphereCollider>();
col.radius = 0.5f;
col.isTrigger = true;
@@ -207,6 +222,52 @@ public class ItemBuilderTool : EditorWindow
Debug.Log($"[ItemBuilder] Префаб сохранён: {path}");
}
// Находит существующий ItemData ассет или создаёт новый — без диалогов
ItemData EnsureItemData()
{
string folder = "Assets/Inventory/Items";
string path = $"{folder}/{itemName}.asset";
var existing = AssetDatabase.LoadAssetAtPath<ItemData>(path);
if (existing != null) return existing;
if (!System.IO.Directory.Exists(folder))
System.IO.Directory.CreateDirectory(folder);
var item = ScriptableObject.CreateInstance<ItemData>();
item.id = string.IsNullOrEmpty(itemId) ? System.Guid.NewGuid().ToString() : itemId;
item.itemName = itemName;
item.description = description;
item.type = itemType;
item.modelPrefab = modelPrefab;
item.icon = icon ?? CreatePlaceholderIcon();
item.maxStack = maxStack;
item.value = value;
item.weight = weight;
item.isDroppable = isDroppable;
item.isStackable = isStackable;
AssetDatabase.CreateAsset(item, path);
AssetDatabase.SaveAssets();
Debug.Log($"[ItemBuilder] ItemData автоматически создан: {path}");
return item;
}
// Добавляет ItemData в InventoryManager.itemDatabase если его там нет
void AddToInventoryDatabase(ItemData data)
{
var im = Object.FindObjectOfType<InventoryManager>();
if (im == null) return;
if (im.itemDatabase == null)
im.itemDatabase = new System.Collections.Generic.List<ItemData>();
if (!im.itemDatabase.Contains(data))
{
im.itemDatabase.Add(data);
EditorUtility.SetDirty(im);
Debug.Log($"[ItemBuilder] {data.itemName} добавлен в InventoryManager.itemDatabase");
}
}
Sprite CreatePlaceholderIcon()
{
var tex = new Texture2D(64, 64);