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

@@ -56,8 +56,8 @@ public class InventoryUIBuilder : MonoBehaviour
GameObject inventoryPanel = CreatePanel("InventoryPanel", transform, inventoryPanelColor);
inventoryPanelRect = inventoryPanel.GetComponent<RectTransform>();
float inventoryWidth = inventoryCols * (slotSize + slotSpacing) + inventoryPadding * 2;
float inventoryHeight = inventoryRows * (slotSize + slotSpacing) + inventoryPadding * 2 + 40;
float inventoryWidth = inventoryCols * slotSize + (inventoryCols - 1) * slotSpacing + inventoryPadding * 2;
float inventoryHeight = inventoryRows * slotSize + (inventoryRows - 1) * slotSpacing + (inventoryPadding + 30) * 2;
inventoryPanelRect.anchorMin = new Vector2(0.5f, 0.5f);
inventoryPanelRect.anchorMax = new Vector2(0.5f, 0.5f);

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);

View File

@@ -219,20 +219,6 @@ public class Slot : MonoBehaviour
// ==================== UI Events ====================
void OnMouseEnter()
{
if (slotBackground != null && !_isSelected)
slotBackground.color = hoverColor;
OnSlotHovered?.Invoke(this);
}
void OnMouseExit()
{
if (slotBackground != null && !_isSelected)
slotBackground.color = IsEmpty ? emptySlotColor : filledSlotColor;
}
void OnMouseDown()
{
if (Input.GetMouseButton(0))

View File

@@ -14,9 +14,24 @@ public class WorldItem : MonoBehaviour
public float interactRange = 2.5f;
private bool _canPickup;
private bool _setupCalled;
void Start()
{
// Объект размещён в сцене через редактор — Setup() не вызывается,
// поэтому инициализируем pickup здесь.
if (!_setupCalled)
{
if (pickupDelay > 0)
Invoke(nameof(EnablePickup), pickupDelay);
else
_canPickup = true;
}
}
public void Setup(ItemData data, int count)
{
_setupCalled = true;
itemData = data;
amount = count;