fix чать инвенторя

This commit is contained in:
jze9
2026-04-16 01:51:46 +05:00
parent 057f5d3d1e
commit 6c3f72385e
35 changed files with 18160 additions and 14313 deletions

View File

@@ -1,30 +1,33 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using TMPro;
/// <summary>
/// Инструмент создания предметов.
/// Tools > Item Builder
/// </summary>
public class ItemBuilderTool : EditorWindow
{
// Основные данные
private string itemName = "NewItem";
private string itemId = "";
private string description = "";
private ItemType itemType = ItemType.Material;
private string itemName = "NewItem";
private string itemId = "";
private string description = "";
private ItemType itemType = ItemType.Material;
// Визуал
private GameObject modelPrefab;
private Sprite icon;
private Color previewColor = Color.gray;
private Sprite icon;
private Color previewColor = Color.gray;
// Свойства
private int maxStack = 64;
private int value = 1;
private float weight = 1f;
private bool isDroppable = true;
private bool isStackable = true;
private int maxStack = 64;
private int value = 1;
private float weight = 1f;
private bool isDroppable = true;
private bool isStackable = true;
// Префаб
private GameObject worldItemPrefab;
// Pickup
private float interactRange = 2.5f;
[MenuItem("Tools/Item Builder")]
public static void ShowWindow()
@@ -38,67 +41,59 @@ public class ItemBuilderTool : EditorWindow
// Основные данные
GUILayout.Label("Основное", EditorStyles.miniBoldLabel);
itemName = EditorGUILayout.TextField("Название", itemName);
itemId = EditorGUILayout.TextField("ID", itemId);
itemName = EditorGUILayout.TextField("Название", itemName);
itemId = EditorGUILayout.TextField("ID (оставь пустым для GUID)", itemId);
description = EditorGUILayout.TextField("Описание", description);
itemType = (ItemType)EditorGUILayout.EnumPopup("Тип предмета", itemType);
itemType = (ItemType)EditorGUILayout.EnumPopup("Тип предмета", itemType);
GUILayout.Space(10);
// Визуал
GUILayout.Label("Визуал", EditorStyles.miniBoldLabel);
modelPrefab = (GameObject)EditorGUILayout.ObjectField("3D модель", modelPrefab, typeof(GameObject), false);
icon = (Sprite)EditorGUILayout.ObjectField("Иконка", icon, typeof(Sprite), false);
modelPrefab = (GameObject)EditorGUILayout.ObjectField("3D модель (префаб)", modelPrefab, typeof(GameObject), false);
icon = (Sprite)EditorGUILayout.ObjectField("Иконка", icon, typeof(Sprite), false);
if (icon == null)
{
previewColor = EditorGUILayout.ColorField("Цвет иконки", previewColor);
}
previewColor = EditorGUILayout.ColorField("Цвет иконки (заглушка)", previewColor);
GUILayout.Space(10);
// Свойства
GUILayout.Label("Свойства", EditorStyles.miniBoldLabel);
maxStack = EditorGUILayout.IntField("Макс. стек", maxStack);
value = EditorGUILayout.IntField("Цена", value);
weight = EditorGUILayout.FloatField("Вес", weight);
maxStack = EditorGUILayout.IntField("Макс. стек", maxStack);
value = EditorGUILayout.IntField("Цена", value);
weight = EditorGUILayout.FloatField("Вес", weight);
isDroppable = EditorGUILayout.Toggle("Можно выбросить", isDroppable);
isStackable = EditorGUILayout.Toggle("Стек", isStackable);
isStackable = EditorGUILayout.Toggle("Стекируемый", isStackable);
GUILayout.Space(10);
// Префаб
GUILayout.Label("Префаб предмета в мире", EditorStyles.miniBoldLabel);
worldItemPrefab = (GameObject)EditorGUILayout.ObjectField("WorldItem Prefab", worldItemPrefab, typeof(GameObject), false);
GUILayout.Label("Подбор", EditorStyles.miniBoldLabel);
interactRange = EditorGUILayout.FloatField("Дальность подбора (E)", interactRange);
GUILayout.Space(20);
// Кнопки
GUI.color = Color.green;
if (GUILayout.Button("Создать ItemData"))
{
if (GUILayout.Button("Создать ItemData (ScriptableObject)"))
CreateItemData();
}
GUI.color = Color.cyan;
if (GUILayout.Button("Создать WorldItem в сцене"))
{
CreateWorldItem();
}
GUI.color = Color.yellow;
if (GUILayout.Button("Создать префаб"))
{
if (GUILayout.Button("Создать WorldItem как префаб"))
CreateItemPrefab();
}
GUI.color = Color.white;
GUILayout.Space(10);
EditorGUILayout.HelpBox(
"1. Заполните данные предмета\n" +
"2. Назначьте модель и иконку\n" +
"3. Создайте ItemData или префаб",
"Подбор предметов — только по кнопке E (авто-pickup при касании убран намеренно).\n" +
"1. Заполните данные → Создайте ItemData\n" +
"2. Назначьте ItemData в InventoryManager.itemDatabase\n" +
"3. Создайте WorldItem для размещения предметов на сцене",
MessageType.Info);
}
@@ -112,105 +107,101 @@ public class ItemBuilderTool : EditorWindow
var item = ScriptableObject.CreateInstance<ItemData>();
item.id = string.IsNullOrEmpty(itemId) ? GUID.Generate().ToString() : itemId;
item.itemName = itemName;
item.id = string.IsNullOrEmpty(itemId) ? System.Guid.NewGuid().ToString() : itemId;
item.itemName = itemName;
item.description = description;
item.type = itemType;
item.type = itemType;
item.modelPrefab = modelPrefab;
item.icon = icon != null ? icon : CreatePlaceholderIcon();
item.maxStack = maxStack;
item.value = value;
item.weight = weight;
item.icon = icon != null ? icon : CreatePlaceholderIcon();
item.maxStack = maxStack;
item.value = value;
item.weight = weight;
item.isDroppable = isDroppable;
item.isStackable = isStackable;
// Сохраняем
string path = $"Assets/Inventory/Items/{itemName}.asset";
string folder = System.IO.Path.GetDirectoryName(path);
string folder = "Assets/Inventory/Items";
if (!System.IO.Directory.Exists(folder))
{
System.IO.Directory.CreateDirectory(folder);
}
string path = $"{folder}/{itemName}.asset";
AssetDatabase.CreateAsset(item, path);
AssetDatabase.SaveAssets();
Selection.activeObject = item;
Debug.Log($"[ItemBuilder] Создан: {itemName}");
Debug.Log($"[ItemBuilder] Создан: {itemName} → {path}");
}
void CreateWorldItem()
{
if (modelPrefab == null)
var itemGO = new GameObject(itemName);
// Визуал
GameObject visual;
if (modelPrefab != null)
{
// Создаём простой визуал
var itemGO = new GameObject(itemName);
var visual = GameObject.CreatePrimitive(PrimitiveType.Cube);
visual.name = "Visual";
visual.transform.SetParent(itemGO.transform);
visual.transform.localPosition = Vector3.zero;
visual.transform.localScale = Vector3.one * 0.3f;
DestroyImmediate(visual.GetComponent<Collider>());
var worldItem = itemGO.AddComponent<WorldItem>();
var col = itemGO.AddComponent<SphereCollider>();
col.radius = 0.5f;
col.isTrigger = true;
itemGO.transform.position = Vector3.zero;
Selection.activeGameObject = itemGO;
visual = (GameObject)PrefabUtility.InstantiatePrefab(modelPrefab, itemGO.transform);
}
else
{
var itemGO = Instantiate(modelPrefab);
itemGO.name = itemName;
itemGO.AddComponent<WorldItem>();
itemGO.transform.position = Vector3.zero;
Selection.activeGameObject = itemGO;
visual = GameObject.CreatePrimitive(PrimitiveType.Cube);
visual.transform.SetParent(itemGO.transform, false);
visual.transform.localScale = Vector3.one * 0.3f;
DestroyImmediate(visual.GetComponent<Collider>());
}
visual.name = "Visual";
visual.transform.localPosition = Vector3.zero;
// WorldItem компонент
var worldItem = itemGO.AddComponent<WorldItem>();
worldItem.interactRange = interactRange;
// Trigger-коллайдер для OverlapSphere (не для авто-pickup!)
var col = itemGO.AddComponent<SphereCollider>();
col.radius = 0.5f;
col.isTrigger = true;
itemGO.transform.position = Vector3.zero;
Selection.activeGameObject = itemGO;
Debug.Log($"[ItemBuilder] Создан WorldItem: {itemName}");
}
void CreateItemPrefab()
{
string path = EditorUtility.SaveFilePanelInProject(
"Сохранить префаб",
"Сохранить WorldItem префаб",
itemName,
"prefab",
"Выберите место");
"Выберите место сохранения");
if (string.IsNullOrEmpty(path)) return;
GameObject prefab;
var prefabGO = new GameObject(itemName);
// Визуал
GameObject visual;
if (modelPrefab != null)
{
prefab = Instantiate(modelPrefab);
prefab.name = itemName;
visual = (GameObject)PrefabUtility.InstantiatePrefab(modelPrefab, prefabGO.transform);
}
else
{
prefab = new GameObject(itemName);
var visual = GameObject.CreatePrimitive(PrimitiveType.Cube);
visual.name = "Visual";
visual.transform.SetParent(prefab.transform);
visual.transform.localPosition = Vector3.zero;
visual = GameObject.CreatePrimitive(PrimitiveType.Cube);
visual.transform.SetParent(prefabGO.transform, false);
visual.transform.localScale = Vector3.one * 0.3f;
DestroyImmediate(visual.GetComponent<Collider>());
}
visual.name = "Visual";
visual.transform.localPosition = Vector3.zero;
prefab.AddComponent<WorldItem>();
var worldItem = prefabGO.AddComponent<WorldItem>();
worldItem.interactRange = interactRange;
var col = prefab.GetComponent<Collider>();
if (col == null)
{
var sphere = prefab.AddComponent<SphereCollider>();
sphere.radius = 0.5f;
sphere.isTrigger = true;
}
var col = prefabGO.AddComponent<SphereCollider>();
col.radius = 0.5f;
col.isTrigger = true;
GameObject savedPrefab = PrefabUtility.SaveAsPrefabAsset(prefab, path);
DestroyImmediate(prefab);
GameObject savedPrefab = PrefabUtility.SaveAsPrefabAsset(prefabGO, path);
DestroyImmediate(prefabGO);
Selection.activeObject = savedPrefab;
Debug.Log($"[ItemBuilder] Префаб сохранён: {path}");
@@ -218,14 +209,12 @@ public class ItemBuilderTool : EditorWindow
Sprite CreatePlaceholderIcon()
{
var tex = new Texture2D(64, 64);
var tex = new Texture2D(64, 64);
var colors = new Color[64 * 64];
for (int i = 0; i < colors.Length; i++)
{
colors[i] = previewColor;
}
tex.SetPixels(colors);
tex.Apply();
return Sprite.Create(tex, new Rect(0, 0, 64, 64), new Vector2(0.5f, 0.5f));
}
}
}