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

@@ -1,135 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4546282257700047937
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1948853633481286021}
- component: {fileID: 6658874805278007762}
- component: {fileID: 3056228376157587138}
m_Layer: 0
m_Name: NewItem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1948853633481286021
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4546282257700047937}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 7434756968248499828}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &6658874805278007762
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4546282257700047937}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b8ac54fbf9ed99e45a83319443952a91, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::WorldItem
itemData: {fileID: 0}
amount: 1
pickupDelay: 0
interactRange: 2.5
--- !u!135 &3056228376157587138
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4546282257700047937}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!1001 &1495056769490629797
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 1948853633481286021}
m_Modifications:
- target: {fileID: 282714382156279063, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
propertyPath: m_Name
value: Visual
objectReference: {fileID: 0}
- target: {fileID: 8327738622413892305, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8327738622413892305, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8327738622413892305, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8327738622413892305, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8327738622413892305, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8327738622413892305, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8327738622413892305, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8327738622413892305, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8327738622413892305, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8327738622413892305, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
--- !u!4 &7434756968248499828 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 8327738622413892305, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
m_PrefabInstance: {fileID: 1495056769490629797}
m_PrefabAsset: {fileID: 0}

View File

@@ -10,14 +10,14 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5741b63764436354ebad192c9b71f06c, type: 3}
m_Name: NewItem
m_Name: newItem
m_EditorClassIdentifier: Assembly-CSharp::ItemData
id: d28a3db9-17bd-489d-9caf-739005a7c780
itemName: NewItem
description: 123
id: c58a6ea4-f064-4392-becd-3b4c2b17cd06
itemName: newItem
description: 123123
type: 5
modelPrefab: {fileID: 282714382156279063, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
icon: {fileID: 21300000, guid: 0115b2d990086ae4cbc31baf7c64e680, type: 3}
icon: {fileID: 0}
maxStack: 64
isCraftable: 0
craftingRecipe:

View File

@@ -0,0 +1,31 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5741b63764436354ebad192c9b71f06c, type: 3}
m_Name: ferstitem
m_EditorClassIdentifier: Assembly-CSharp::ItemData
id: c3b1d462-dc84-4d7a-8463-34ffbde783d9
itemName: ferstitem
description: ferstitem
type: 5
modelPrefab: {fileID: 282714382156279063, guid: 4fcbba5b8725e254f98c052c4db89e02, type: 3}
icon: {fileID: 21300000, guid: 0115b2d990086ae4cbc31baf7c64e680, type: 3}
maxStack: 64
isCraftable: 0
craftingRecipe:
ingredients: []
amounts:
resultId:
resultAmount: 1
weight: 1
value: 1
isDroppable: 1
isStackable: 1

View File

@@ -1,7 +1,8 @@
fileFormatVersion: 2
guid: 9f444e9048146434087c3db3550617f9
PrefabImporter:
guid: d870f627519521f4aa24b9a36766465d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,31 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5741b63764436354ebad192c9b71f06c, type: 3}
m_Name: ferstitem123
m_EditorClassIdentifier: Assembly-CSharp::ItemData
id: 4b147ba6-462a-4f90-9d00-29089fed390a
itemName: ferstitem123
description: 123
type: 5
modelPrefab: {fileID: 8569222662204961130, guid: 06e51a4df39df524397e91edba2a833d, type: 3}
icon: {fileID: 21300000, guid: 0115b2d990086ae4cbc31baf7c64e680, type: 3}
maxStack: 64
isCraftable: 0
craftingRecipe:
ingredients: []
amounts:
resultId:
resultAmount: 1
weight: 1
value: 1
isDroppable: 1
isStackable: 1

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5db581fdeb06daf4da37cb3d6f32b5ff
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

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;