From 672c064e6ee4334cacf113d02d56450deb48b325 Mon Sep 17 00:00:00 2001 From: Ash Blue Date: Sat, 11 Jan 2025 13:19:51 -0800 Subject: [PATCH] fix(item creation): no longer crashes when `_displayName` field is missing --- Assets/Examples/Resources/ItemDatabase.asset | 1 + Assets/Examples/Shop/Definitions/CustomItem.asset | 15 +++++++++++++++ .../Shop/Definitions/CustomItem.asset.meta | 8 ++++++++ .../ItemDefinitionCustomDisplayName.cs | 12 ++++++++++++ .../ItemDefinitionCustomDisplayName.cs.meta | 3 +++ .../Editor/Components/Pages/PageItemDatabase.cs | 8 +++++++- 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Assets/Examples/Shop/Definitions/CustomItem.asset create mode 100644 Assets/Examples/Shop/Definitions/CustomItem.asset.meta create mode 100644 Assets/Examples/Shop/Scripts/Definitions/ItemDefinitionCustomDisplayName.cs create mode 100644 Assets/Examples/Shop/Scripts/Definitions/ItemDefinitionCustomDisplayName.cs.meta diff --git a/Assets/Examples/Resources/ItemDatabase.asset b/Assets/Examples/Resources/ItemDatabase.asset index 838d617..5c02548 100644 --- a/Assets/Examples/Resources/ItemDatabase.asset +++ b/Assets/Examples/Resources/ItemDatabase.asset @@ -14,6 +14,7 @@ MonoBehaviour: m_EditorClassIdentifier: _autoLoad: 1 _definitions: + - {fileID: 11400000, guid: 80d3b6ab2a78e6b418da8aed88e32926, type: 2} - {fileID: 11400000, guid: d3988ba3f8a2c44e6a1b98201ce75ee2, type: 2} - {fileID: 11400000, guid: 4e2438a1b36c043e587e88575d07b5ff, type: 2} - {fileID: 11400000, guid: 5e7593ddbeb614a3984bd7fcc9251406, type: 2} diff --git a/Assets/Examples/Shop/Definitions/CustomItem.asset b/Assets/Examples/Shop/Definitions/CustomItem.asset new file mode 100644 index 0000000..31e8495 --- /dev/null +++ b/Assets/Examples/Shop/Definitions/CustomItem.asset @@ -0,0 +1,15 @@ +%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: e149b91f3de145dc9820a3c795b7b05a, type: 3} + m_Name: CustomItem + m_EditorClassIdentifier: + _id: fe563339-c771-4245-9db6-3b38dccf7426 diff --git a/Assets/Examples/Shop/Definitions/CustomItem.asset.meta b/Assets/Examples/Shop/Definitions/CustomItem.asset.meta new file mode 100644 index 0000000..4cbb35e --- /dev/null +++ b/Assets/Examples/Shop/Definitions/CustomItem.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 80d3b6ab2a78e6b418da8aed88e32926 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Examples/Shop/Scripts/Definitions/ItemDefinitionCustomDisplayName.cs b/Assets/Examples/Shop/Scripts/Definitions/ItemDefinitionCustomDisplayName.cs new file mode 100644 index 0000000..25b1ba8 --- /dev/null +++ b/Assets/Examples/Shop/Scripts/Definitions/ItemDefinitionCustomDisplayName.cs @@ -0,0 +1,12 @@ +using CleverCrow.Fluid.ElasticInventory; + +namespace CleverCrow.Fluid.Examples { + /// + /// Simulates creating a custom display name and category for an item definition + /// + [ItemDefinitionDetails("Custom Display Details")] + public class ItemDefinitionCustomDisplayName : ItemDefinitionBase { + public override string DisplayName => "Custom Display Name"; + public override string Category => "Custom Category"; + } +} diff --git a/Assets/Examples/Shop/Scripts/Definitions/ItemDefinitionCustomDisplayName.cs.meta b/Assets/Examples/Shop/Scripts/Definitions/ItemDefinitionCustomDisplayName.cs.meta new file mode 100644 index 0000000..15f27ef --- /dev/null +++ b/Assets/Examples/Shop/Scripts/Definitions/ItemDefinitionCustomDisplayName.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e149b91f3de145dc9820a3c795b7b05a +timeCreated: 1736629859 \ No newline at end of file diff --git a/Assets/com.fluid.elastic-inventory/Editor/Components/Pages/PageItemDatabase.cs b/Assets/com.fluid.elastic-inventory/Editor/Components/Pages/PageItemDatabase.cs index cd5f8dd..9c77ee4 100644 --- a/Assets/com.fluid.elastic-inventory/Editor/Components/Pages/PageItemDatabase.cs +++ b/Assets/com.fluid.elastic-inventory/Editor/Components/Pages/PageItemDatabase.cs @@ -95,7 +95,13 @@ void CreateItemDefinition (ItemDatabase database, Type type) { var serializedObject = new SerializedObject(itemDefinition); var fileName = System.IO.Path.GetFileNameWithoutExtension(path); - serializedObject.FindProperty("_displayName").stringValue = MakeSpacedWord(fileName); + + // Set the display name to be the spaced version of the file name (if it exists) + var displayName = serializedObject.FindProperty("_displayName"); + if (displayName != null) { + displayName.stringValue = MakeSpacedWord(fileName); + } + // @TODO Duplicate IDs are inevitable due to object cloning, repair them automatically when refreshing asset references serializedObject.FindProperty("_id").stringValue = Guid.NewGuid().ToString(); serializedObject.ApplyModifiedPropertiesWithoutUndo();