From 7f4aec84b3f1dbcb041cc72fd9fc7569c7037560 Mon Sep 17 00:00:00 2001 From: kabix09 Date: Sat, 19 Nov 2022 17:02:31 +0100 Subject: [PATCH] Panel refactoring - chest & make chast dynamics --- .../Chest.meta => Resources/Chests.meta} | 0 .../Chests}/Gold Chest.prefab | 35 ++- .../Chests}/Gold Chest.prefab.meta | 0 .../Chests}/Prize Chest.prefab | 33 +-- .../Chests}/Prize Chest.prefab.meta | 0 .../Chests}/Wooden Chest.prefab | 33 +-- .../Chests}/Wooden Chest.prefab.meta | 0 Assets/{ => Resources}/Items.meta | 2 +- Assets/{ => Resources}/Items/Axe.asset | 0 Assets/{ => Resources}/Items/Axe.asset.meta | 0 Assets/{ => Resources}/Items/Axe.prefab | 0 Assets/{ => Resources}/Items/Axe.prefab.meta | 0 Assets/{ => Resources}/Items/Gold Ore.asset | 0 .../{ => Resources}/Items/Gold Ore.asset.meta | 0 Assets/{ => Resources}/Items/Gold Ore.prefab | 0 .../Items/Gold Ore.prefab.meta | 0 Assets/{ => Resources}/Items/Pickaxe.asset | 0 .../{ => Resources}/Items/Pickaxe.asset.meta | 0 Assets/{ => Resources}/Items/Pickaxe.prefab | 0 .../{ => Resources}/Items/Pickaxe.prefab.meta | 0 .../UiPanels/ChestPanel.prefab} | 34 ++- .../UiPanels/ChestPanel.prefab.meta} | 0 .../UiPanels/ChestSlot.prefab} | 2 +- .../UiPanels/ChestSlot.prefab.meta} | 0 Assets/Scripts/Chest/ChestController.cs | 116 -------- Assets/Scripts/Chest/ChestPanelController.cs | 55 ---- .../{ => REFACTORING/Application}/Chest.meta | 2 +- .../Application/Chest/ChestController.cs | 29 ++ .../Chest/ChestController.cs.meta | 2 +- .../Application/Chest/SceneChestBuilder.cs | 48 +++ .../Chest/SceneChestBuilder.cs.meta} | 2 +- .../Panel/Chest/ChestDataListManager.cs | 28 +- .../Panel/Chest/SaveChestManager.cs | 99 +++++++ .../Panel/Chest/SaveChestManager.cs.meta | 11 + .../Panel/Chest/SceneChestDataLoader.cs | 122 ++++++++ .../Panel/Chest/SceneChestDataLoader.cs.meta | 11 + .../Panel/Chest/SceneChestDataManager.cs | 133 +++++++++ .../Panel/Chest/SceneChestDataManager.cs.meta | 11 + .../Inventory/InventoryDataListManager.cs | 11 +- .../Inventory/SceneInventoryDataLoader.cs | 75 ----- .../Inventory/SceneInventoryDataManager.cs | 12 +- .../Application/Panel/SceneChestManager.cs | 80 ----- .../Panel/SceneChestManager.cs.meta | 3 - .../Application/Panel/Task/SaveTaskManager.cs | 2 +- .../Panel/Task/SceneTaskDataLoader.cs | 4 +- .../Panel/Task/SceneTaskDataManager.cs | 11 +- .../Panel/Task/TaskDataListManager.cs | 16 +- .../Shared/Manager/Buildable.meta} | 2 +- .../Manager/Buildable/SceneObjectBuilder.cs | 26 ++ .../Buildable/SceneObjectBuilder.cs.meta | 11 + .../Buildable/SceneObjectBuilderInterface.cs | 15 + .../SceneObjectBuilderInterface.cs.meta | 11 + .../Shared/Manager/DataListManager.cs | 2 - .../Manager/Panel/SceneBaseDataManager.cs | 36 +-- .../Panel/SceneDataListManagerInterface.cs | 2 - .../Draggable/DraggablePanelController.cs | 32 +- .../Draggable/DraggablePanelInterface.cs | 2 - .../Panel/Draggable/DraggedSlotController.cs | 9 +- .../WarehousePanelController.cs | 37 +++ .../Shared/Manager/UI/UIBaseManager.cs | 41 +-- .../Shared/Manager/UI/UIWarehouseManager.cs | 29 +- .../REFACTORING/Application/UI}/Chest.meta | 2 +- .../UI/Chest/ChestContentUIManager.cs | 112 +++++++ .../UI/Chest/ChestContentUIManager.cs.meta | 11 + .../Application/UI/Chest/ChestUIManager.cs | 100 +++++++ .../UI/Chest/ChestUIManager.cs.meta | 11 + .../UI/Inventory/InventoryUIManager.cs | 26 +- .../UI/Panel/ChestPanelController.cs | 91 ++++++ .../UI/Panel}/ChestPanelController.cs.meta | 2 +- .../UI/Panel/InventoryPanelController.cs | 2 +- .../REFACTORING/Domain/Enum/ChestTypeEnum.cs | 10 + .../Domain/Enum/ChestTypeEnum.cs.meta | 11 + Assets/Scripts/REFACTORING/Models.meta | 3 + Assets/Scripts/REFACTORING/Models/Chest.meta | 8 + .../Scripts/REFACTORING/Models/Chest/Chest.cs | 106 +++++++ .../REFACTORING/Models/Chest/Chest.cs.meta | 11 + .../REFACTORING/Models/Chest/ChestData.cs | 64 ++++ .../Models/Chest/ChestData.cs.meta | 11 + .../Models/Chest/ChestPrefabAsset.cs | 29 ++ .../Models/Chest/ChestPrefabAsset.cs.meta | 11 + .../Models/Chest/ChestPrefabAssetData.cs | 60 ++++ .../Models/Chest/ChestPrefabAssetData.cs.meta | 11 + .../Item/EquippableItem/EquippableItem.cs | 20 +- .../Item/EquippableItem/EquippableItemData.cs | 42 +-- .../EquippableItemPrefabAssetData.cs | 8 +- .../REFACTORING/Models/Item/ItemData.cs | 73 +++-- .../Models/Panel/Slot}/ChestSlot.cs | 6 + .../Models/Panel/Slot}/ChestSlot.cs.meta | 0 .../REFACTORING/Models/Panel/Slot/ISlot.cs | 6 +- .../Models/Panel/Slot/InventorySlot.cs | 5 + .../REFACTORING/Models/Panel/Slot/ItemSlot.cs | 24 +- Assets/Scripts/REFACTORING/Models/Scene.meta | 3 - .../REFACTORING/Models/Shared/ModelData.cs | 39 +++ .../Models/Shared/ModelData.cs.meta | 11 + .../Models/Shared/PrefabAssetModelData.cs | 22 +- Assets/Scripts/SceneManager/SaveChest.meta | 8 - .../SceneManager/SaveChest/ChestData.meta | 8 - .../SaveChest/ChestPrefarbAsset.cs | 26 -- .../SaveChest/ChestPrefarbAssetData.cs | 54 ---- .../SaveChest/ChestPrefarbAssetData.cs.meta | 11 - .../SceneManager/SaveChest/SaveChestSystem.cs | 105 ------- .../SaveChest/SaveChestSystem.cs.meta | 11 - .../Scripts/SceneManager/SceneChestManager.cs | 273 ------------------ .../SceneManager/SceneChestManager.cs.meta | 11 - .../SceneEquippableItemManager.cs | 56 ++-- 105 files changed, 1627 insertions(+), 1164 deletions(-) rename Assets/{Items/Chest.meta => Resources/Chests.meta} (100%) rename Assets/{Items/Chest => Resources/Chests}/Gold Chest.prefab (93%) rename Assets/{Items/Chest => Resources/Chests}/Gold Chest.prefab.meta (100%) rename Assets/{Items/Chest => Resources/Chests}/Prize Chest.prefab (94%) rename Assets/{Items/Chest => Resources/Chests}/Prize Chest.prefab.meta (100%) rename Assets/{Items/Chest => Resources/Chests}/Wooden Chest.prefab (94%) rename Assets/{Items/Chest => Resources/Chests}/Wooden Chest.prefab.meta (100%) rename Assets/{ => Resources}/Items.meta (77%) rename Assets/{ => Resources}/Items/Axe.asset (100%) rename Assets/{ => Resources}/Items/Axe.asset.meta (100%) rename Assets/{ => Resources}/Items/Axe.prefab (100%) rename Assets/{ => Resources}/Items/Axe.prefab.meta (100%) rename Assets/{ => Resources}/Items/Gold Ore.asset (100%) rename Assets/{ => Resources}/Items/Gold Ore.asset.meta (100%) rename Assets/{ => Resources}/Items/Gold Ore.prefab (100%) rename Assets/{ => Resources}/Items/Gold Ore.prefab.meta (100%) rename Assets/{ => Resources}/Items/Pickaxe.asset (100%) rename Assets/{ => Resources}/Items/Pickaxe.asset.meta (100%) rename Assets/{ => Resources}/Items/Pickaxe.prefab (100%) rename Assets/{ => Resources}/Items/Pickaxe.prefab.meta (100%) rename Assets/{Prefarbs/Chest/chest_panel.prefab => Resources/UiPanels/ChestPanel.prefab} (96%) rename Assets/{Prefarbs/Chest/chest_panel.prefab.meta => Resources/UiPanels/ChestPanel.prefab.meta} (100%) rename Assets/{Prefarbs/Chest/chest_slot.prefab => Resources/UiPanels/ChestSlot.prefab} (99%) rename Assets/{Prefarbs/Chest/chest_slot.prefab.meta => Resources/UiPanels/ChestSlot.prefab.meta} (100%) delete mode 100644 Assets/Scripts/Chest/ChestController.cs delete mode 100644 Assets/Scripts/Chest/ChestPanelController.cs rename Assets/Scripts/{ => REFACTORING/Application}/Chest.meta (77%) create mode 100644 Assets/Scripts/REFACTORING/Application/Chest/ChestController.cs rename Assets/Scripts/{ => REFACTORING/Application}/Chest/ChestController.cs.meta (83%) create mode 100644 Assets/Scripts/REFACTORING/Application/Chest/SceneChestBuilder.cs rename Assets/Scripts/{SceneManager/SaveChest/ChestPrefarbAsset.cs.meta => REFACTORING/Application/Chest/SceneChestBuilder.cs.meta} (83%) create mode 100644 Assets/Scripts/REFACTORING/Application/Panel/Chest/SaveChestManager.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Panel/Chest/SaveChestManager.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataLoader.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataLoader.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataManager.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataManager.cs.meta delete mode 100644 Assets/Scripts/REFACTORING/Application/Panel/SceneChestManager.cs delete mode 100644 Assets/Scripts/REFACTORING/Application/Panel/SceneChestManager.cs.meta rename Assets/{Prefarbs/Inventory UI.meta => Scripts/REFACTORING/Application/Shared/Manager/Buildable.meta} (77%) create mode 100644 Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilder.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilder.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilderInterface.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilderInterface.cs.meta rename Assets/{Prefarbs => Scripts/REFACTORING/Application/UI}/Chest.meta (77%) create mode 100644 Assets/Scripts/REFACTORING/Application/UI/Chest/ChestContentUIManager.cs create mode 100644 Assets/Scripts/REFACTORING/Application/UI/Chest/ChestContentUIManager.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/UI/Chest/ChestUIManager.cs create mode 100644 Assets/Scripts/REFACTORING/Application/UI/Chest/ChestUIManager.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/UI/Panel/ChestPanelController.cs rename Assets/Scripts/{Chest => REFACTORING/Application/UI/Panel}/ChestPanelController.cs.meta (83%) create mode 100644 Assets/Scripts/REFACTORING/Domain/Enum/ChestTypeEnum.cs create mode 100644 Assets/Scripts/REFACTORING/Domain/Enum/ChestTypeEnum.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Models.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Chest.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Chest/Chest.cs create mode 100644 Assets/Scripts/REFACTORING/Models/Chest/Chest.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Chest/ChestData.cs create mode 100644 Assets/Scripts/REFACTORING/Models/Chest/ChestData.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAsset.cs create mode 100644 Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAsset.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAssetData.cs create mode 100644 Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAssetData.cs.meta rename Assets/Scripts/{Chest => REFACTORING/Models/Panel/Slot}/ChestSlot.cs (83%) rename Assets/Scripts/{Chest => REFACTORING/Models/Panel/Slot}/ChestSlot.cs.meta (100%) delete mode 100644 Assets/Scripts/REFACTORING/Models/Scene.meta create mode 100644 Assets/Scripts/REFACTORING/Models/Shared/ModelData.cs create mode 100644 Assets/Scripts/REFACTORING/Models/Shared/ModelData.cs.meta delete mode 100644 Assets/Scripts/SceneManager/SaveChest.meta delete mode 100644 Assets/Scripts/SceneManager/SaveChest/ChestData.meta delete mode 100644 Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAsset.cs delete mode 100644 Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAssetData.cs delete mode 100644 Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAssetData.cs.meta delete mode 100644 Assets/Scripts/SceneManager/SaveChest/SaveChestSystem.cs delete mode 100644 Assets/Scripts/SceneManager/SaveChest/SaveChestSystem.cs.meta delete mode 100644 Assets/Scripts/SceneManager/SceneChestManager.cs delete mode 100644 Assets/Scripts/SceneManager/SceneChestManager.cs.meta diff --git a/Assets/Items/Chest.meta b/Assets/Resources/Chests.meta similarity index 100% rename from Assets/Items/Chest.meta rename to Assets/Resources/Chests.meta diff --git a/Assets/Items/Chest/Gold Chest.prefab b/Assets/Resources/Chests/Gold Chest.prefab similarity index 93% rename from Assets/Items/Chest/Gold Chest.prefab rename to Assets/Resources/Chests/Gold Chest.prefab index 8a5d00a6..b9a34278 100644 --- a/Assets/Items/Chest/Gold Chest.prefab +++ b/Assets/Resources/Chests/Gold Chest.prefab @@ -11,6 +11,7 @@ GameObject: - component: {fileID: 805898525} - component: {fileID: 805898527} - component: {fileID: 805898526} + - component: {fileID: 5462276123095309683} m_Layer: 0 m_Name: Chest1-InteractionMSG m_TagString: Untagged @@ -28,6 +29,7 @@ Transform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0.095890045, y: -0.058502197, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 4669568061092186073} m_RootOrder: 0 @@ -70,6 +72,18 @@ MonoBehaviour: _tmpPanelAbove: {fileID: 0} obj: {fileID: 4669568061092186072} isAllowedToShowPanels: 1 +--- !u!114 &5462276123095309683 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 805898524} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a532f2b712a01fc4fad02346f1a69e39, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &4669568061092186072 GameObject: m_ObjectHideFlags: 0 @@ -81,7 +95,6 @@ GameObject: - component: {fileID: 4669568061092186073} - component: {fileID: 4669568061092186078} - component: {fileID: 4669568061092186079} - - component: {fileID: 4669568061092186076} m_Layer: 0 m_Name: Gold Chest m_TagString: Untagged @@ -99,6 +112,7 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 58.59589, y: 32.941498, z: 20} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 805898525} m_Father: {fileID: 0} @@ -115,6 +129,7 @@ SpriteRenderer: m_CastShadows: 0 m_ReceiveShadows: 0 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -166,7 +181,7 @@ BoxCollider2D: m_Density: 1 m_Material: {fileID: 0} m_IsTrigger: 0 - m_UsedByEffector: 0 + m_UsedByEffector: 1 m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} m_SpriteTilingProperty: @@ -181,19 +196,3 @@ BoxCollider2D: serializedVersion: 2 m_Size: {x: 0.95, y: 0.9} m_EdgeRadius: 0 ---- !u!114 &4669568061092186076 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 4669568061092186072} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 26a44ba4cba1985408fca11ba424361c, type: 3} - m_Name: - m_EditorClassIdentifier: - _panel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} - isOpen: 0 - chest: {fileID: 0} - developerList: [] diff --git a/Assets/Items/Chest/Gold Chest.prefab.meta b/Assets/Resources/Chests/Gold Chest.prefab.meta similarity index 100% rename from Assets/Items/Chest/Gold Chest.prefab.meta rename to Assets/Resources/Chests/Gold Chest.prefab.meta diff --git a/Assets/Items/Chest/Prize Chest.prefab b/Assets/Resources/Chests/Prize Chest.prefab similarity index 94% rename from Assets/Items/Chest/Prize Chest.prefab rename to Assets/Resources/Chests/Prize Chest.prefab index e3fd6d5d..2c1839c9 100644 --- a/Assets/Items/Chest/Prize Chest.prefab +++ b/Assets/Resources/Chests/Prize Chest.prefab @@ -11,6 +11,7 @@ GameObject: - component: {fileID: 584661738} - component: {fileID: 584661740} - component: {fileID: 584661739} + - component: {fileID: 6369310084342855511} m_Layer: 0 m_Name: Chest0-InteractionMSG m_TagString: Untagged @@ -28,6 +29,7 @@ Transform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0.19999695, z: -1.8041458} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 5754902894522036728} m_RootOrder: 0 @@ -70,6 +72,18 @@ MonoBehaviour: _tmpPanelAbove: {fileID: 0} obj: {fileID: 5754902894522036729} isAllowedToShowPanels: 1 +--- !u!114 &6369310084342855511 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 584661737} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a532f2b712a01fc4fad02346f1a69e39, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &5754902894522036729 GameObject: m_ObjectHideFlags: 0 @@ -81,7 +95,6 @@ GameObject: - component: {fileID: 5754902894522036728} - component: {fileID: 5754902894522036731} - component: {fileID: 5754902894522036730} - - component: {fileID: 5754902894522036733} m_Layer: 0 m_Name: Prize Chest m_TagString: Untagged @@ -99,6 +112,7 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 16, y: 51.2, z: 18.195854} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 584661738} m_Father: {fileID: 0} @@ -115,6 +129,7 @@ SpriteRenderer: m_CastShadows: 0 m_ReceiveShadows: 0 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -181,19 +196,3 @@ BoxCollider2D: serializedVersion: 2 m_Size: {x: 1.35, y: 1.1} m_EdgeRadius: 0 ---- !u!114 &5754902894522036733 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 5754902894522036729} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 26a44ba4cba1985408fca11ba424361c, type: 3} - m_Name: - m_EditorClassIdentifier: - _panel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} - isOpen: 0 - chest: {fileID: 0} - developerList: [] diff --git a/Assets/Items/Chest/Prize Chest.prefab.meta b/Assets/Resources/Chests/Prize Chest.prefab.meta similarity index 100% rename from Assets/Items/Chest/Prize Chest.prefab.meta rename to Assets/Resources/Chests/Prize Chest.prefab.meta diff --git a/Assets/Items/Chest/Wooden Chest.prefab b/Assets/Resources/Chests/Wooden Chest.prefab similarity index 94% rename from Assets/Items/Chest/Wooden Chest.prefab rename to Assets/Resources/Chests/Wooden Chest.prefab index 7e8062d1..8d061a27 100644 --- a/Assets/Items/Chest/Wooden Chest.prefab +++ b/Assets/Resources/Chests/Wooden Chest.prefab @@ -11,6 +11,7 @@ GameObject: - component: {fileID: 1698721847} - component: {fileID: 1698721849} - component: {fileID: 1698721848} + - component: {fileID: 3574830714698708195} m_Layer: 0 m_Name: Chest3-InteractionMSG m_TagString: Untagged @@ -28,6 +29,7 @@ Transform: 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: [] m_Father: {fileID: 3972494989842158580} m_RootOrder: 0 @@ -70,6 +72,18 @@ MonoBehaviour: _tmpPanelAbove: {fileID: 0} obj: {fileID: 3972494989842158579} isAllowedToShowPanels: 1 +--- !u!114 &3574830714698708195 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1698721846} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a532f2b712a01fc4fad02346f1a69e39, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &3972494989842158579 GameObject: m_ObjectHideFlags: 0 @@ -82,7 +96,6 @@ GameObject: - component: {fileID: 3972494989842158473} - component: {fileID: 3972494989842158583} - component: {fileID: 3972494989842158582} - - component: {fileID: 3972494989842158581} m_Layer: 0 m_Name: Wooden Chest m_TagString: Untagged @@ -100,6 +113,7 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: -8.45, y: -3.9, z: 10} m_LocalScale: {x: 0.5, y: 0.5, z: 1} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 1698721847} m_Father: {fileID: 0} @@ -116,6 +130,7 @@ SpriteRenderer: m_CastShadows: 0 m_ReceiveShadows: 0 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -208,19 +223,3 @@ BoxCollider2D: serializedVersion: 2 m_Size: {x: 0.95, y: 1.5900776} m_EdgeRadius: 0 ---- !u!114 &3972494989842158581 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 3972494989842158579} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 26a44ba4cba1985408fca11ba424361c, type: 3} - m_Name: - m_EditorClassIdentifier: - _panel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} - isOpen: 0 - chest: {fileID: 0} - developerList: [] diff --git a/Assets/Items/Chest/Wooden Chest.prefab.meta b/Assets/Resources/Chests/Wooden Chest.prefab.meta similarity index 100% rename from Assets/Items/Chest/Wooden Chest.prefab.meta rename to Assets/Resources/Chests/Wooden Chest.prefab.meta diff --git a/Assets/Items.meta b/Assets/Resources/Items.meta similarity index 77% rename from Assets/Items.meta rename to Assets/Resources/Items.meta index cd34b519..c192d4e6 100644 --- a/Assets/Items.meta +++ b/Assets/Resources/Items.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b0e1c4df7cd61824384676c2e7fb2991 +guid: a592c74dcbbaafa4a82cc20d574cb331 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Items/Axe.asset b/Assets/Resources/Items/Axe.asset similarity index 100% rename from Assets/Items/Axe.asset rename to Assets/Resources/Items/Axe.asset diff --git a/Assets/Items/Axe.asset.meta b/Assets/Resources/Items/Axe.asset.meta similarity index 100% rename from Assets/Items/Axe.asset.meta rename to Assets/Resources/Items/Axe.asset.meta diff --git a/Assets/Items/Axe.prefab b/Assets/Resources/Items/Axe.prefab similarity index 100% rename from Assets/Items/Axe.prefab rename to Assets/Resources/Items/Axe.prefab diff --git a/Assets/Items/Axe.prefab.meta b/Assets/Resources/Items/Axe.prefab.meta similarity index 100% rename from Assets/Items/Axe.prefab.meta rename to Assets/Resources/Items/Axe.prefab.meta diff --git a/Assets/Items/Gold Ore.asset b/Assets/Resources/Items/Gold Ore.asset similarity index 100% rename from Assets/Items/Gold Ore.asset rename to Assets/Resources/Items/Gold Ore.asset diff --git a/Assets/Items/Gold Ore.asset.meta b/Assets/Resources/Items/Gold Ore.asset.meta similarity index 100% rename from Assets/Items/Gold Ore.asset.meta rename to Assets/Resources/Items/Gold Ore.asset.meta diff --git a/Assets/Items/Gold Ore.prefab b/Assets/Resources/Items/Gold Ore.prefab similarity index 100% rename from Assets/Items/Gold Ore.prefab rename to Assets/Resources/Items/Gold Ore.prefab diff --git a/Assets/Items/Gold Ore.prefab.meta b/Assets/Resources/Items/Gold Ore.prefab.meta similarity index 100% rename from Assets/Items/Gold Ore.prefab.meta rename to Assets/Resources/Items/Gold Ore.prefab.meta diff --git a/Assets/Items/Pickaxe.asset b/Assets/Resources/Items/Pickaxe.asset similarity index 100% rename from Assets/Items/Pickaxe.asset rename to Assets/Resources/Items/Pickaxe.asset diff --git a/Assets/Items/Pickaxe.asset.meta b/Assets/Resources/Items/Pickaxe.asset.meta similarity index 100% rename from Assets/Items/Pickaxe.asset.meta rename to Assets/Resources/Items/Pickaxe.asset.meta diff --git a/Assets/Items/Pickaxe.prefab b/Assets/Resources/Items/Pickaxe.prefab similarity index 100% rename from Assets/Items/Pickaxe.prefab rename to Assets/Resources/Items/Pickaxe.prefab diff --git a/Assets/Items/Pickaxe.prefab.meta b/Assets/Resources/Items/Pickaxe.prefab.meta similarity index 100% rename from Assets/Items/Pickaxe.prefab.meta rename to Assets/Resources/Items/Pickaxe.prefab.meta diff --git a/Assets/Prefarbs/Chest/chest_panel.prefab b/Assets/Resources/UiPanels/ChestPanel.prefab similarity index 96% rename from Assets/Prefarbs/Chest/chest_panel.prefab rename to Assets/Resources/UiPanels/ChestPanel.prefab index 47b5c828..c36de0ab 100644 --- a/Assets/Prefarbs/Chest/chest_panel.prefab +++ b/Assets/Resources/UiPanels/ChestPanel.prefab @@ -29,8 +29,8 @@ RectTransform: 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_Children: - - {fileID: 5331092056807707113} + m_ConstrainProportionsScale: 0 + m_Children: [] m_Father: {fileID: 5331092055037629063} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -101,9 +101,9 @@ GameObject: - component: {fileID: 5331092055018478732} - component: {fileID: 5331092055018478730} - component: {fileID: 5331092055018478731} - - component: {fileID: 4617582679355695156} + - component: {fileID: 2117488037472856852} m_Layer: 5 - m_Name: chest_panel + m_Name: ChestPanel m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -119,10 +119,12 @@ RectTransform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.4, y: 0.4, z: 0.4} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 5331092055896533710} - {fileID: 5331092055037629063} - {fileID: 5331092055143140113} + - {fileID: 5331092056807707113} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -169,7 +171,7 @@ MonoBehaviour: m_FillOrigin: 0 m_UseSpriteMesh: 0 m_PixelsPerUnitMultiplier: 1 ---- !u!114 &4617582679355695156 +--- !u!114 &2117488037472856852 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -178,15 +180,12 @@ MonoBehaviour: m_GameObject: {fileID: 5331092055018478733} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 8d9e1061a8038f54a87269aa0bd2db04, type: 3} + m_Script: {fileID: 11500000, guid: 84da00f00bb500c46b1e5629ca4a61b8, type: 3} m_Name: m_EditorClassIdentifier: - _panel: {fileID: 5331092056807707114} - _blankSlot: {fileID: 3818338910890019850, guid: e2f95cfb3084e6e4f9f16c14170adfb5, type: 3} - _panelCloseButton: {fileID: 5331092055143140112} - _tmp: {fileID: 0} - _itemTemplate: {fileID: 6570396142606985298, guid: 1304511dd1dfefc449e87c3d904ab15f, type: 3} - chest: {fileID: 0} + _panelContent: {fileID: 5331092056807707114} + ChildBoxTemplate: {fileID: 3818338910890019850, guid: e2f95cfb3084e6e4f9f16c14170adfb5, type: 3} + ChildBoxList: [] --- !u!1 &5331092055037629064 GameObject: m_ObjectHideFlags: 0 @@ -216,6 +215,7 @@ RectTransform: 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: 5331092054895676294} m_Father: {fileID: 5331092055018478732} @@ -323,6 +323,7 @@ RectTransform: 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: [] m_Father: {fileID: 5331092055018478732} m_RootOrder: 2 @@ -442,6 +443,7 @@ RectTransform: 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: [] m_Father: {fileID: 5331092055896533710} m_RootOrder: 0 @@ -576,6 +578,7 @@ RectTransform: 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: 5331092055455069025} m_Father: {fileID: 5331092055018478732} @@ -652,13 +655,14 @@ RectTransform: 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: [] - m_Father: {fileID: 5331092054895676294} - m_RootOrder: 0 + m_Father: {fileID: 5331092055018478732} + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: 0.000024795532} + m_AnchoredPosition: {x: 0, y: 0.000030517578} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 1} --- !u!114 &5331092056807707111 diff --git a/Assets/Prefarbs/Chest/chest_panel.prefab.meta b/Assets/Resources/UiPanels/ChestPanel.prefab.meta similarity index 100% rename from Assets/Prefarbs/Chest/chest_panel.prefab.meta rename to Assets/Resources/UiPanels/ChestPanel.prefab.meta diff --git a/Assets/Prefarbs/Chest/chest_slot.prefab b/Assets/Resources/UiPanels/ChestSlot.prefab similarity index 99% rename from Assets/Prefarbs/Chest/chest_slot.prefab rename to Assets/Resources/UiPanels/ChestSlot.prefab index 952980e7..b0927dc9 100644 --- a/Assets/Prefarbs/Chest/chest_slot.prefab +++ b/Assets/Resources/UiPanels/ChestSlot.prefab @@ -150,7 +150,7 @@ GameObject: - component: {fileID: 7379342322136183382} - component: {fileID: 8625463808668959803} m_Layer: 5 - m_Name: chest_slot + m_Name: ChestSlot m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/Assets/Prefarbs/Chest/chest_slot.prefab.meta b/Assets/Resources/UiPanels/ChestSlot.prefab.meta similarity index 100% rename from Assets/Prefarbs/Chest/chest_slot.prefab.meta rename to Assets/Resources/UiPanels/ChestSlot.prefab.meta diff --git a/Assets/Scripts/Chest/ChestController.cs b/Assets/Scripts/Chest/ChestController.cs deleted file mode 100644 index 9832b1c4..00000000 --- a/Assets/Scripts/Chest/ChestController.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class ChestController : BaseWarehouseController -{ - [SerializeField] public GameObject chest; - [SerializeField] public List developerList = new List(); // FOR DEVELOPER TESTE - remove later !!! - - bool isTrigerred = false; - - // Start is called before the first frame update - void Start() - { - chest = gameObject; // set object on current GameObject - - // FOR DEVELOPER TESTE - remove later !!! - for(int i = 0; i < developerList.Count; i++) - { - SetItemOnPosition(i, developerList[i]); - } - } - - // Update is called once per frame - void Update() - { - if (this._panel && this.isTrigerred && !this.isOpen) // we can open chest only when its closed - { - if (Input.GetKeyDown(KeyCode.E)) - { - this.OpenPanel(); - InventoryManager.Instance.OpenPanel(); - EquipmentManager.Instance.OpenPanel(); - } - } - - if (!InventoryManager.Instance.isOpen) - { - if (Input.GetKeyDown(KeyCode.I)) - { - InventoryManager.Instance.OpenPanel(); - } - } - - } - - void OnTriggerExit2D(Collider2D collision) - { - if (this._panel != null) - { - this.ClosePanel(); - } - - this.isTrigerred = false; - } - - private void OnTriggerEnter2D(Collider2D collision) - { - if (collision.tag == "Player") - { - this.isTrigerred = true; - } - } - - - public override void ClosePanel() - { - base.ClosePanel(); - InventoryManager.Instance.ClosePanel(); - EquipmentManager.Instance.ClosePanel(); - } - - protected override void SetupPanel() - { - if(this.dynamicPanel) - { - this.dynamicPanel.GetComponent().Setup(gameObject, _items); - } - } - // WARNING - // DANGER - functon override position which may be not free - - /// - /// Function for placed item in inventory on SPECYFIC position - /// Used by SceneInventoryManager for load saved items on their positions - /// - - // WHAT WITH FUNCTION - setupItemOnPosition() - ??? - public void SetupItemInChest(int key, EquippableItem pickable) - { - this._items[key] = pickable; - } - - public override void SetItemOnPosition(int _keyPosition, Item _item) - { - // Drag setup first end second object on the same panel - should only one - this wwere dropped item - // Becouse of this source slot from other panel is settuping in dropped panel too - list get empty item and it cause errors - if(_item != null) - { - this._items[_keyPosition] = _item; -Debug.Log("Put item on chest"+_item.name); - // Inform Map Chests manager about update - update list to be compliant with the local list - SceneChestManager.Instance.AddItemToChest(gameObject.name, _keyPosition, (EquippableItem)_item); - } - // if we assign null its removed later in EndDrag method - } - - public override void RemoveItemFromPosition(int _keyPosition) - { - base.RemoveItemFromPosition(_keyPosition); -Debug.Log("Pick up item from chest"); - - // Inform Map Chests manager about update - update list to be compliant with the local list - SceneChestManager.Instance.RemoveItemFromChest(gameObject.name, _keyPosition); - } -} diff --git a/Assets/Scripts/Chest/ChestPanelController.cs b/Assets/Scripts/Chest/ChestPanelController.cs deleted file mode 100644 index 4f781678..00000000 --- a/Assets/Scripts/Chest/ChestPanelController.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; -using UnityEngine.EventSystems; -using System; - -public class ChestPanelController : BasePanelController -{ - public override void CloseOnClick() - { - Destroy(gameObject); // destroy panel - - if(_instance) - { - _instance.GetComponent().ClosePanel(); - } - } - - public void Setup(GameObject _chest, Dictionary _chestItems) - { - _instance = _chest; - - base.Setup(_chestItems); - } - - protected override ISlot SetupSlot(int key, GameObject _parent) - { - ChestSlot _tmpSlot = Instantiate(_blankSlot, _parent.transform.position, Quaternion.identity).GetComponent(); - - _tmpSlot.transform.SetParent(_parent.transform); - - _tmpSlot.SetupSlot(key, null, this); - - return _tmpSlot; - } - - -// Islot - > Aslot -// - > B slots - -// Ipanel -> Apanel -// -> B panel - - - // --------------------------- - // will work differently depending if its chest, inventory or equipment panel - // public void Equip(EquippableItem item) - // { - // if(RemoveItem(item)) - // { - // EquippableItem previousItem; - // } - // } -} diff --git a/Assets/Scripts/Chest.meta b/Assets/Scripts/REFACTORING/Application/Chest.meta similarity index 77% rename from Assets/Scripts/Chest.meta rename to Assets/Scripts/REFACTORING/Application/Chest.meta index b09fcec1..a9b29aad 100644 --- a/Assets/Scripts/Chest.meta +++ b/Assets/Scripts/REFACTORING/Application/Chest.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c7042c6d06a175543b01bd0e9d316f53 +guid: 888d1783775092f48b15c03485e1562a folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/REFACTORING/Application/Chest/ChestController.cs b/Assets/Scripts/REFACTORING/Application/Chest/ChestController.cs new file mode 100644 index 00000000..727057da --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Chest/ChestController.cs @@ -0,0 +1,29 @@ +using UnityEditor; +using UnityEngine; + +public class ChestController : MonoBehaviour +{ + public void Update() + { + } + + + private void OnTriggerStay2D(Collider2D collision) + { + if (collision.tag == "Player") + { + ChestUIManager.Instance.CurrentChestName = gameObject.transform.parent.name; + } + } + + + private void OnTriggerExit2D(Collider2D collision) + { + if (collision.tag == "Player") + { + ChestUIManager.Instance.CurrentChestName = null; + + ChestUIManager.Instance.ClosePanel(); + } + } +} diff --git a/Assets/Scripts/Chest/ChestController.cs.meta b/Assets/Scripts/REFACTORING/Application/Chest/ChestController.cs.meta similarity index 83% rename from Assets/Scripts/Chest/ChestController.cs.meta rename to Assets/Scripts/REFACTORING/Application/Chest/ChestController.cs.meta index 80857311..d967306d 100644 --- a/Assets/Scripts/Chest/ChestController.cs.meta +++ b/Assets/Scripts/REFACTORING/Application/Chest/ChestController.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 26a44ba4cba1985408fca11ba424361c +guid: a532f2b712a01fc4fad02346f1a69e39 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/REFACTORING/Application/Chest/SceneChestBuilder.cs b/Assets/Scripts/REFACTORING/Application/Chest/SceneChestBuilder.cs new file mode 100644 index 00000000..33a698eb --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Chest/SceneChestBuilder.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections; +using UnityEngine; + +[Serializable] +public class SceneChestBuilder : SceneObjectBuilder +{ + [SerializeField] int trest = 0; + protected override string MODEL_SOURCE_PATH { get { return "Chests/"; } } + + public override void Build(ChestPrefabAsset objectToBuild) + { + GameObject globalGUI = GameObject.FindGameObjectsWithTag("GUI")[0]; + + if (!globalGUI) + Debug.LogError("GUI frame not found!!"); + + + GameObject newObject = FindModel(objectToBuild.Chest.chestModel.name); + + Debug.Log($"Chest {newObject} - name: {objectToBuild.Chest.chestModel.name}"); + + if (!newObject) + Debug.LogError("Can't find prefarb by name " + objectToBuild.Chest.chestModel.name); + + // Build chest on map + GameObject chest = Instantiate(newObject, objectToBuild.Position, Quaternion.identity, globalGUI.transform); + + chest.name = objectToBuild.Chest.Name; + chest.transform.localScale = new Vector3(0.5f, 0.5f, 1f); + chest.transform.localPosition = objectToBuild.Position; + + + // data about chest cpontent should be handled in SceneChestManager class and pass to ChestUIPanel only after opening Panel by Player + // in other words objects dont have full info about its data xd + // confuse and irrational but this way it will be easiet to maintain Data Consistency + } + + public override GameObject FindModel(string modelName) + { + var resource = Resources.Load(MODEL_SOURCE_PATH + modelName); + + if (!resource) + throw new System.Exception($"Resource {MODEL_SOURCE_PATH + modelName} not found!!"); + + return resource; + } +} diff --git a/Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAsset.cs.meta b/Assets/Scripts/REFACTORING/Application/Chest/SceneChestBuilder.cs.meta similarity index 83% rename from Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAsset.cs.meta rename to Assets/Scripts/REFACTORING/Application/Chest/SceneChestBuilder.cs.meta index 86ee0041..0cc1761b 100644 --- a/Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAsset.cs.meta +++ b/Assets/Scripts/REFACTORING/Application/Chest/SceneChestBuilder.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b770806e2f537ac4ab266a6629ae2fd2 +guid: 3db499bc88166ac409489e99ce706c8d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Chest/ChestDataListManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Chest/ChestDataListManager.cs index 831b245a..9e575c69 100644 --- a/Assets/Scripts/REFACTORING/Application/Panel/Chest/ChestDataListManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Panel/Chest/ChestDataListManager.cs @@ -1,23 +1,27 @@ using UnityEngine; +using System.Collections.Generic; -public class ChestDataListManager : SceneDataListManager +public class ChestDataListManager : DataListManager // or maybe EquippableItem - but its get conflicts... { - public ChestDataListManager(string gameObjectLocalization, string assetLocalization) : base(gameObjectLocalization, assetLocalization) + [SerializeField] protected new ChestUIManager uiManager; + + public new DataListManager SetUiManager(ref ChestUIManager _uiManager) { + uiManager = _uiManager; + + return this; } - public override void AddElementToList(ChestPrefarbAsset newElement) + + public override void AddElementToList(ChestPrefabAsset newElement) + { + Elements.Add(newElement); + } + + public override void RemoveElementFromList(ChestPrefabAsset element) { throw new System.NotImplementedException(); } - public override void RemoveElementFromList(ChestPrefarbAsset element) - { - throw new System.NotImplementedException(); - } - - protected override void doBuild(GameObject _object) - { - throw new System.NotImplementedException(); - } + //public void AddElement } diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Chest/SaveChestManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Chest/SaveChestManager.cs new file mode 100644 index 00000000..ce5aa603 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Chest/SaveChestManager.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using UnityEngine; + +public class SaveChestManager : SaveModelSystem +{ + public override bool SaveModelItem(ChestPrefabAsset model) + { + return base.SaveModelItem(model); + } + + public override bool SaveModelList(List list) + { + BinaryFormatter formatter = new BinaryFormatter(); + + Debug.Log("Saved Chest at " + Path); + + if (!Directory.Exists(Path)) Directory.CreateDirectory(Path); + + /* Main logic of conversion data format */ + var data = ConvertObjectsListToListOfDataModels(list); + + FileStream stream = new FileStream( + Path + GetFileName(ObjectListName), + FileMode.Create + ); + + formatter.Serialize(stream, data); + stream.Close(); + + return true; + } + + public override ChestPrefabAsset LoadModelItem() + { + return base.LoadModelItem(); + } + + public override List LoadModelList() + { + string path = Path + GetFileName(ObjectListName); + + if (File.Exists(path)) + { + BinaryFormatter formatter = new BinaryFormatter(); + FileStream stream = new FileStream(path, FileMode.Open); + + List questsList = formatter.Deserialize(stream) as List; + stream.Close(); + + return ConvertListOfDataModelsToListOfObject(questsList); + } + else + { + Debug.Log("Save file not found in " + path); + } + + return new List(); + } + + // Support function + + // 1. From model to data format + private ChestPrefabAssetData ConvertObjectToDataModel(ChestPrefabAsset model) + { + return new ChestPrefabAssetData(model); + } + + private List ConvertObjectsListToListOfDataModels(List modelsList) + { + List convertedList = new List(); + + foreach(ChestPrefabAsset model in modelsList) + { + convertedList.Add(ConvertObjectToDataModel(model)); + } + + return convertedList; + } + + // 2. From data to model format + private ChestPrefabAsset ConvertDataModelToObject(ChestPrefabAssetData dataModel) + { + return (ChestPrefabAsset)dataModel.MapDataToPrefabAssetModel(); + } + + private List ConvertListOfDataModelsToListOfObject(List dataModelsList) + { + List convertedList = new List(); + + foreach (ChestPrefabAssetData dataModel in dataModelsList) + { + convertedList.Add(ConvertDataModelToObject(dataModel)); + } + + return convertedList; + } +} \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Chest/SaveChestManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Chest/SaveChestManager.cs.meta new file mode 100644 index 00000000..48c01ad8 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Chest/SaveChestManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 33ba3be2d80a64440ac0f48c05695285 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataLoader.cs b/Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataLoader.cs new file mode 100644 index 00000000..ea050981 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataLoader.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +public class SceneChestDataLoader : SceneBaseDataLoader +{ + public SceneChestDataLoader(string _objectListName, string _objectFolderName) + { + SaveModelSystem = new SaveChestManager(); + SaveModelSystem.ObjectFolderName = _objectFolderName; + SaveModelSystem.ObjectListName = _objectListName; + } + + /* + public void LoadInventoryItemsList() + { + string path = SaveSystem.GetSavePath(); + + if (!Directory.Exists(path)) // if not exists thats mean there was nothing saved yet - nothing to load + return; + + FileInfo[] fileInfo = new DirectoryInfo(path).GetFiles(); + + foreach(FileInfo file in fileInfo) + { + if(file.Name != this.ItemsListName + ".fun") + continue; + + Dictionary equippableItemsList = SaveInventorySystem.LoadInventoryItemsList(this.ItemsListName); + + // itemEntry.Value.MapDataToObject() - map data format to object + + // save object + foreach(KeyValuePair itemEntry in equippableItemsList) + { + InventoryManager.Instance.SetupItemInInventory(itemEntry.Key, itemEntry.Value.MapDataToEquippableItemPrefarbAsset().equippableItem); + } + } + } + + public void SaveInventoryItems() + { + // Case I - if we remember all list + // 1) if after removed item form DynamicList is empty - remove all file + // 2) if after removed item form DynamciList there are another one - save updated list again + if(InventoryManager.Instance._items.Count > 0) { + + // 1. Map From Dictionary' to 'Dictionary' + Dictionary mappedList = new Dictionary(); + + foreach(KeyValuePair itemElement in InventoryManager.Instance._items) + { + mappedList[itemElement.Key] = new EquippableItemPrefabAsset( + itemElement.Value.Name, + itemElement.Value.ItemModel.name, + new Vector3(0,0,0), + (EquippableItem) itemElement.Value + ); + } + + // 2. Save Items + SaveInventorySystem.SaveInventoryItemsList(mappedList, this.ItemsListName); + } else { + string _path = SaveSystem.GetSavePath() + "/" + this.ItemsListName + ".fun"; + + try + { + Debug.Log("File to remove: " + _path); + + if(File.Exists(_path)) + { + File.Delete(_path); + } + } + catch (IOException ioExp) + { + Debug.LogError(ioExp.Message); + } + } + + // Case II - if we rememenber object per file + // 1) remove specyfic file + // + // Unfortunatelly we don't use this way of saving items yet :D + } + */ + + + + protected override List LoadStaticData() { throw new System.NotImplementedException(); } + + protected override List LoadDynamicData() + { + SaveModelSystem.Path = PathBuilder.BuildSavePath().WithMap(CurrentMap).WithDataType(SceneElementTypeEnum.Dynamic).GetString(); + + return SaveModelSystem.LoadModelList(); + } + + protected override bool SaveStaticData(List _elements) { throw new System.NotImplementedException(); } + + protected override bool SaveDynamicData(List _elements) + { + SaveModelSystem.Path = PathBuilder.BuildSavePath().WithMap(CurrentMap).WithDataType(SceneElementTypeEnum.Dynamic).GetString(); + + Debug.Log(SaveModelSystem.Path); + +/* try + {*/ + SaveModelSystem.SaveModelList(_elements); + + return true; +/* } + catch (Exception e) { Debug.LogError(e.Message); }*/ + + return false; + } + + protected override List LoadGenericData() { throw new NotImplementedException(); } + + protected override bool SaveGenericData(List _elements) { throw new NotImplementedException(); } +} diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataLoader.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataLoader.cs.meta new file mode 100644 index 00000000..7703b350 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d3926d80a4de1b7449f0346556a1b07d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataManager.cs new file mode 100644 index 00000000..5f92fe29 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataManager.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +[Serializable] +public class SceneChestDataManager : SceneBaseDataManager +{ + protected override string OBJECT_FOLDER_NAME { get { return "Chest"; } } + protected override string OBJECT_LIST_NAME { get { return "ChestList"; } } + + //protected new SceneBaseDataLoader DataLoader { get; set; } + protected SceneChestBuilder ChestBuilder { get; set; } + + + + [SerializeField] Chest CurrentChest; + + [SerializeField] public List ElementsToBuildOnSceneList = new List(); + + + [SerializeField] List convertDataToAsset = new List(); + + + // tmp var + bool NewGame = false; + + public override void Awake() + { + if (Instance == null) + { + + Instance = this; + } + else + { + Destroy(gameObject); + } + } + + private void Start() + { + Debug.Log("Start SceneChestData manager"); + + //TaskUIManager.FindOrCreateInstance(); + var chestManager = ChestUIManager.Instance; + + if (chestManager == null) + throw new NullReferenceException("ChestUIManager not found!!!"); + + StaticDataList = (new ChestDataListManager()).SetUiManager(ref chestManager); + DynamicDataList = (new ChestDataListManager()).SetUiManager(ref chestManager); + + DataLoader = new SceneChestDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME); + + ChestBuilder = new SceneChestBuilder(); + //ChestBuilder.ElementsToBuildOnSceneList = ElementsToBuildOnSceneList; + + //SaveData(StaticDataList.GetList(), SceneElementTypeEnum.None); + + //LoadData(SceneElementTypeEnum.None, ref StaticDataList); + // LoadDynamicData(); + + //inventoryManager.SetList(StaticDataList.GetList()); + + //inventoryManager.OpenPanel(); + + if (NewGame) + { + foreach (ChestPrefabAssetData asset in ElementsToBuildOnSceneList) { convertDataToAsset.Add((ChestPrefabAsset)asset.MapDataToPrefabAssetModel()); } + + ChestBuilder.ElementsToBuildOnSceneList = convertDataToAsset; + ChestBuilder.BuildList(); + + + DynamicDataList.SetList(convertDataToAsset); + + List tmp = new List(); + foreach (ChestPrefabAsset asset in ChestBuilder.ElementsToBuildOnSceneList) { tmp.Add(asset.Chest); } + + chestManager.SetList(tmp); + } + else + { + LoadDynamicData(); + + ChestBuilder.ElementsToBuildOnSceneList = DynamicDataList.GetList(); + ChestBuilder.BuildList(); + + List tmp = new List(); + foreach (ChestPrefabAsset asset in ChestBuilder.ElementsToBuildOnSceneList) { tmp.Add(asset.Chest); } + + chestManager.SetList(tmp); + + + + // BuildList(); + + // when chest detect player in near arrea and player press "c" + // open panel -> chest controller handle Open panel in Scene Chest Manager passing info about what Chest Palyer want to open + // Manager Build panel and pass info about chest content + } + } + + // TODO - save ChestPrefabAsset (we need to save coords...) but in manager handle Chest data.. + // + + + + protected SceneBaseDataManager GetObjectType() + { + return GameObject.FindObjectOfType(); + } + + protected SceneBaseDataManager CreateInstance(ref GameObject managerGameObject) + { + return managerGameObject.AddComponent(); + } + + + // TODO manager api + // open panel extend function + // close panel extend function + + public void OpenPanel(string chestName) + { + + } + // TODO chest api + // add to chest - find chest by its name np + // remove from chest - select chest by its name - + // chesk item in chest - check chest by tis name + +} diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataManager.cs.meta new file mode 100644 index 00000000..a672e860 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Panel/Chest/SceneChestDataManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c0b2d7931c00ea64eb1da159de0455e0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/InventoryDataListManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/InventoryDataListManager.cs index 43006db4..5cefa38e 100644 --- a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/InventoryDataListManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/InventoryDataListManager.cs @@ -1,8 +1,9 @@ using System.Collections.Generic; +using UnityEngine; public class InventoryDataListManager : DataListManager> // or maybe EquippableItem - but its get conflicts... { - public DataListManager> SetUiManager(ref UIWarehouseManager _uiManager) + public new DataListManager> SetUiManager(ref InventoryUIManager _uiManager) { uiManager = _uiManager; @@ -18,12 +19,4 @@ public class InventoryDataListManager : DataListManager> { throw new System.NotImplementedException(); } - - // public override void Build() - // { - // // pass to InventoryManager singleton - // foreach(KeyValuePair itemEntry in Elements) - // InventoryManager.Instance.SetupItemInInventory(itemEntry.Key, itemEntry.Value.equippableItem); - // - // } } diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataLoader.cs b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataLoader.cs index d738712f..b0d071c2 100644 --- a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataLoader.cs +++ b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataLoader.cs @@ -12,81 +12,6 @@ public class SceneInventoryDataLoader : SceneBaseDataLoader equippableItemsList = SaveInventorySystem.LoadInventoryItemsList(this.ItemsListName); - - // itemEntry.Value.MapDataToEquippableItem() - map data format to object - - // save object - foreach(KeyValuePair itemEntry in equippableItemsList) - { - InventoryManager.Instance.SetupItemInInventory(itemEntry.Key, itemEntry.Value.MapDataToEquippableItemPrefarbAsset().equippableItem); - } - } - } - - public void SaveInventoryItems() - { - // Case I - if we remember all list - // 1) if after removed item form DynamicList is empty - remove all file - // 2) if after removed item form DynamciList there are another one - save updated list again - if(InventoryManager.Instance._items.Count > 0) { - - // 1. Map From Dictionary' to 'Dictionary' - Dictionary mappedList = new Dictionary(); - - foreach(KeyValuePair itemElement in InventoryManager.Instance._items) - { - mappedList[itemElement.Key] = new EquippableItemPrefabAsset( - itemElement.Value.Name, - itemElement.Value.ItemModel.name, - new Vector3(0,0,0), - (EquippableItem) itemElement.Value - ); - } - - // 2. Save Items - SaveInventorySystem.SaveInventoryItemsList(mappedList, this.ItemsListName); - } else { - string _path = SaveSystem.GetSavePath() + "/" + this.ItemsListName + ".fun"; - - try - { - Debug.Log("File to remove: " + _path); - - if(File.Exists(_path)) - { - File.Delete(_path); - } - } - catch (IOException ioExp) - { - Debug.LogError(ioExp.Message); - } - } - - // Case II - if we rememenber object per file - // 1) remove specyfic file - // - // Unfortunatelly we don't use this way of saving items yet :D - } - */ - - protected override List> LoadGenericData() { SaveModelSystem.Path = PathBuilder.BuildSavePath().GetString(); diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataManager.cs index 31ccc153..0d41229f 100644 --- a/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Panel/Inventory/SceneInventoryDataManager.cs @@ -28,12 +28,12 @@ public class SceneInventoryDataManager : SceneBaseDataManager -// { -// private new const string STATIC_ELEMENT_LOCATION = "/StaticElements/"; -// private new const string ELEMENT_FOLDER_NAME = "Chest"; -// private new const string ITEM_LIST_NAME = "ChestList"; -// -// // [SerializeField] -// // public List StaticElements; -// // -// // [SerializeField] -// // public List DynamicElements; -// -// public override void AddElementToList() -// { -// throw new System.NotImplementedException(); -// } -// -// public override void RemoveElementFromList() -// { -// throw new System.NotImplementedException(); -// } -// -// public override void Build() -// { -// throw new System.NotImplementedException(); -// } -// -// public override void LoadData() -// { -// this.StaticElements = LoadStaticChestsList(); -// } -// -// #region Static list of Chest Loader -// private List LoadStaticChestsList() -// { -// var path = SaveSystem.GetSavePath(this.MapName + STATIC_ELEMENT_LOCATION); -// -// if (!Directory.Exists(path)) -// return new List(); -// -// List chestPrefabAssetList = new List(); -// -// foreach(var file in new DirectoryInfo(path).GetFiles()) -// { -// Debug.Log(file.FullName); -// -// List chestPrefabAssetDataList = SaveChestSystem.LoadChestsList(this.MapName + STATIC_ELEMENT_LOCATION, ITEM_LIST_NAME); -// -// chestPrefabAssetList = chestPrefabAssetDataList.Select(chestPrefabAssetData => chestPrefabAssetData.MapDataToChestPrefarbAsset()).ToList(); -// -// // Debug.Log("---- Load Chest"); -// // -// // foreach(ChestPrefarbAsset chest in chestPrefarbAssetList) -// // { -// // Debug.Log(chest.name); -// // foreach(KeyValuePair equippableItemPrefarbAsset in chest.content) -// // { -// // // Debug.Log("item on position " + equippableItemPrefarbAsset.Key + -// // // " " + equippableItemPrefarbAsset.Value.equippableItem.name); -// // } -// // } -// -// } -// -// return chestPrefabAssetList; -// } -// #endregion -// } -// } \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Panel/SceneChestManager.cs.meta b/Assets/Scripts/REFACTORING/Application/Panel/SceneChestManager.cs.meta deleted file mode 100644 index e7f42125..00000000 --- a/Assets/Scripts/REFACTORING/Application/Panel/SceneChestManager.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 03ae14a03c0d4cfb83ddf5c7eb84c528 -timeCreated: 1660171923 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Task/SaveTaskManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Task/SaveTaskManager.cs index e3ba8959..ba40ab40 100644 --- a/Assets/Scripts/REFACTORING/Application/Panel/Task/SaveTaskManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Panel/Task/SaveTaskManager.cs @@ -34,7 +34,7 @@ public class SaveTaskDataManager : SaveModelSystem return base.LoadModelItem(); } - public override IEnumerable LoadModelList() + public override List LoadModelList() { string path = Path + GetFileName(ObjectListName); diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataLoader.cs b/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataLoader.cs index 6960b6bb..b940d99f 100644 --- a/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataLoader.cs +++ b/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataLoader.cs @@ -66,7 +66,7 @@ public class SceneTaskDataLoader : SceneBaseDataLoader // // } - protected override IEnumerable LoadGenericData() + protected override List LoadGenericData() { SaveModelSystem.Path = PathBuilder.BuildSavePath().GetString(); @@ -88,7 +88,7 @@ public class SceneTaskDataLoader : SceneBaseDataLoader return false; } - protected override IEnumerable LoadStaticData() { throw new System.NotImplementedException(); } + protected override List LoadStaticData() { throw new System.NotImplementedException(); } protected override List LoadDynamicData() { throw new System.NotImplementedException(); } diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataManager.cs index f9a6821a..6b1532b0 100644 --- a/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Panel/Task/SceneTaskDataManager.cs @@ -20,12 +20,13 @@ public class SceneTaskDataManager : SceneBaseDataManager // DynamicDataList = (new TaskDataListManager()).SetUiManager(ref taskManager); DataLoader = new SceneTaskDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME); - - // taskManager.SetList(); - LoadStaticData(); - // LoadDynamicData(); - taskManager.SetList(StaticDataList.GetList()); + // taskManager.SetList(); + //SaveData(taskManager.GetList(), SceneElementTypeEnum.None); + + + //LoadData(SceneElementTypeEnum.None, ref StaticDataList); + //taskManager.SetList(StaticDataList.GetList()); } protected SceneBaseDataManager GetObjectType() diff --git a/Assets/Scripts/REFACTORING/Application/Panel/Task/TaskDataListManager.cs b/Assets/Scripts/REFACTORING/Application/Panel/Task/TaskDataListManager.cs index 5aaf0d61..2db928ed 100644 --- a/Assets/Scripts/REFACTORING/Application/Panel/Task/TaskDataListManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Panel/Task/TaskDataListManager.cs @@ -1,10 +1,16 @@ +using UnityEngine; + public class TaskDataListManager : DataListManager { - // public override void Build() - // { - // foreach(var quest in Elements) - // uiManager.Add(quest); - // } + [SerializeField] protected new TaskUIManager uiManager; + + public new DataListManager SetUiManager(ref TaskUIManager _uiManager) + { + uiManager = _uiManager; + + return this; + } + public override void AddElementToList(Task newElement) { throw new System.NotImplementedException(); diff --git a/Assets/Prefarbs/Inventory UI.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable.meta similarity index 77% rename from Assets/Prefarbs/Inventory UI.meta rename to Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable.meta index 2b3edc53..1dde6031 100644 --- a/Assets/Prefarbs/Inventory UI.meta +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5e5b0dc687e02e447a5d3464cc5d7a9d +guid: e3aa9c4c1601f994a96a35cc82056750 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilder.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilder.cs new file mode 100644 index 00000000..9c93d625 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilder.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +[Serializable] +public abstract class SceneObjectBuilder : MonoBehaviour, SceneObjectBuilderInterface +{ + protected virtual string MODEL_SOURCE_PATH => ""; + + /// + /// List of chests deffaultly builded on scene + /// + [SerializeField] public List ElementsToBuildOnSceneList = new List(); + + public virtual void BuildList() + { + foreach(var objectToBuild in ElementsToBuildOnSceneList) + { + Build(objectToBuild); + } + } + + public abstract void Build(V objectToBuild); + + public abstract GameObject FindModel(string modelName); +} diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilder.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilder.cs.meta new file mode 100644 index 00000000..57540c45 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 212b939253830f7418846dd9d0413307 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilderInterface.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilderInterface.cs new file mode 100644 index 00000000..d566cc3b --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilderInterface.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +public interface SceneObjectBuilderInterface +{ + /// + /// Function to find object's model in resources + /// + /// + public GameObject FindModel(string modelName); + + public void BuildList(); + public void Build(T objectToBuild); +} diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilderInterface.cs.meta b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilderInterface.cs.meta new file mode 100644 index 00000000..96745d5c --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Buildable/SceneObjectBuilderInterface.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8679df969e936794c90b5dd15c067620 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/DataListManager.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/DataListManager.cs index 409f1622..9402b663 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/DataListManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/DataListManager.cs @@ -30,6 +30,4 @@ public abstract class DataListManager : SceneDataListManagerInterface public abstract void AddElementToList(T newElement); public abstract void RemoveElementFromList(T element); - - //public abstract void Build(); } diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataManager.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataManager.cs index 651af7f1..22c60484 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataManager.cs @@ -16,18 +16,17 @@ public abstract class SceneBaseDataManager : MonoBehaviour public static SceneBaseDataManager Instance; // { get; private set; } - public static SceneBaseDataManager FindOrCreateInstance() // ref GameObject managerGameObject + public virtual void Awake() { - var instance = GetObjectType(); - if (instance != null) + if (Instance == null) { - return instance; + Instance = this; + } + else + { + Destroy(gameObject); } - - Instance = CreateInstance(); - - return Instance; } protected static SceneBaseDataManager GetObjectType() @@ -54,22 +53,12 @@ public abstract class SceneBaseDataManager : MonoBehaviour return GameObject.FindGameObjectWithTag("Manager").transform.Find("DataManger").gameObject; } - // /// - // /// Part of core functions - // /// - // private void Build() - // { - // // StaticDataList.Build(); - // // - // // DynamicDataList.Build(); - // } - protected virtual bool LoadData(SceneElementTypeEnum type, ref DataListManager dataListManager) { try { dataListManager.SetList( - DataLoader.LoadData(SceneElementTypeEnum.None) as List + DataLoader.LoadData(type) as List ); return true; @@ -85,17 +74,19 @@ public abstract class SceneBaseDataManager : MonoBehaviour { try { + Debug.Log("SaveData"); + Debug.Log(DataLoader); DataLoader.SaveData(_elements, type); return true; } catch (Exception e) { - Debug.LogWarning(e.Message); + Debug.LogError(e.Message); } return false; } - + /// /// Part of static list CURD methods /// @@ -152,10 +143,11 @@ public abstract class SceneBaseDataManager : MonoBehaviour // TODO // how to get list // 1. List in UI manager should be synchronized with list in this manager - + // approach: // 1. get from outside, update local list && us it // 2. Handle list synchronized all the time & pass local list + Debug.Log("SaveDynamicData"); return SaveData(DynamicDataList.GetList(), SceneElementTypeEnum.Dynamic); } diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManagerInterface.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManagerInterface.cs index 37ce467a..fd32afb4 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManagerInterface.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneDataListManagerInterface.cs @@ -9,6 +9,4 @@ public interface SceneDataListManagerInterface public void AddElementToList(T element); public void RemoveElementFromList(T element); - - // public void Build(); } diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelController.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelController.cs index c8157398..2d8fb5cb 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelController.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelController.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using UnityEditor; using UnityEngine; using UnityEngine.UI; @@ -43,19 +44,20 @@ public abstract class DraggablePanelController : PanelController(i, (EquippableItem)ChildBoxList[i].Item)); + UiManager.Add(new KeyValuePair(i, ChildBoxList[i].Item)); } else { @@ -78,29 +80,21 @@ public abstract class DraggablePanelController : PanelController(dropItemSlot.Number, tmpDraggedItem)); - /* - * not sure why but if you change order of assign, something will ovberride dropItemSlot.Item vale accordint to draggedSlot.Item = dropItemSlot.Item; value - * BUG - not sure where - */ - draggedSlot.Item = dropItemSlot.Item; - UiManager.Add(new KeyValuePair(draggedSlot.Number, (EquippableItem)draggedSlot.Item)); - - dropItemSlot.Item = _tmpDraggedItem; - UiManager.Add(new KeyValuePair(dropItemSlot.Number, (EquippableItem)dropItemSlot.Item)); + // !!! remember item from dropped position to future operation !!! + if (dropItem) + DraggedSlotController.Instance.UpdateItem(new EquippableItem(dropItem)); + else + DraggedSlotController.Instance.UpdateItem(null); } } - //public ISlot GetDraggedSlotFromManager() => InventoryUIManager.Instance.DraggedSlot; public ISlot GetDraggedSlot() { return DraggedSlotController.Instance.DraggedSlot; } - - public void SetItemOnPosition() - { - throw new System.NotImplementedException(); - } } \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelInterface.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelInterface.cs index 483abc54..0331c813 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelInterface.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggablePanelInterface.cs @@ -19,7 +19,5 @@ public interface DraggablePanelInterface public void Drop(ItemSlot dropItemSlot); // supports function to use in Drop - public void SetItemOnPosition(); - public ISlot GetDraggedSlot(); } \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggedSlotController.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggedSlotController.cs index 51a21c30..194feca4 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggedSlotController.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/Draggable/DraggedSlotController.cs @@ -13,8 +13,8 @@ public class DraggedSlotController : MonoBehaviour [Space] [Header("Dragged Slot")] - [SerializeField] protected ISlot _draggedSlot; - public ISlot DraggedSlot // in Drag & Drop functionality for Warehouse set of panels I will temporary delegate dragged item to outside static object instance in order to remember it during dragging object from one slot to anothe one + [SerializeField] protected ItemSlot _draggedSlot; + public ItemSlot DraggedSlot // in Drag & Drop functionality for Warehouse set of panels I will temporary delegate dragged item to outside static object instance in order to remember it during dragging object from one slot to anothe one { get { return _draggedSlot; } set @@ -93,4 +93,9 @@ public class DraggedSlotController : MonoBehaviour return true; } + + public void UpdateItem(Item item) + { + DraggedSlot.Item = (EquippableItem)item; + } } \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel/WarehousePanelController.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel/WarehousePanelController.cs index 471c6d23..6ed8e5bf 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel/WarehousePanelController.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/Panel/WarehousePanel/WarehousePanelController.cs @@ -1,10 +1,47 @@ using System; using System.Collections.Generic; +using System.Linq; using UnityEditor; using UnityEngine; public abstract class WarehousePanelController : DraggablePanelController { + public override void EndDrag(ItemSlot itemSlot) + { + if (!DraggedSlotController.Instance.IsDragged()) // if there was nothing dragged - ignore event + return; + + DraggedSlotController.Instance.RemoveDraggedSlot(); + + // 1. Remove from slot - for case where EndDrag and Drop work on differen UiManager's + // Important: clear slot not only reset itemn!!! + if (!itemSlot.Item) + ((ItemSlot)ChildBoxList.Where(slot => slot.Number == itemSlot.Number).First()).ResetSlot(); + else + ((ItemSlot)ChildBoxList.Where(slot => slot.Number == itemSlot.Number).First()).SetItem(itemSlot.Item); + + // 2. Rebuild/apply UiManager content (list of items) base on slots values after its updating + + // 2.1 Make copy because Add -> base.Add() -> base.Add() -> UpdateList() rebuild content ad pass "new" list (in this case with only one - firtst passed - item) to ChestContentUiMangaer.Element + var ChildBoxListCopy = new List>(ChildBoxList.Where(slot => slot.Item != null).Select(slot => new KeyValuePair(slot.Number, slot.Item)).ToList()); + + UiManager.RemoveAll(); + + foreach(KeyValuePair slot in ChildBoxListCopy) + { + if (slot.Value != null) + { + Debug.Log($"Slot nr: {slot.Key} with item: {slot.Value}"); + + UiManager.Add(new KeyValuePair(slot.Key, slot.Value)); + } + else + { + UiManager.RemoveByPosition(slot.Key); + } + } + } + public override void BuildPanelContent(List> elements) { base.BuildPanelContent(elements); diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIBaseManager.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIBaseManager.cs index a621117c..c9ad475f 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIBaseManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIBaseManager.cs @@ -5,10 +5,10 @@ using UnityEngine; [Serializable] public abstract class UIBaseManager : MonoBehaviour, ManagerInterface { - public static UIBaseManager Instance { get; private set; } + public static UIBaseManager Instance { get; protected set; } - [SerializeField] protected GameObject DynamicPanel; + [SerializeField] public GameObject DynamicPanel; [SerializeField] public KeyCode keyToOpen; @@ -22,8 +22,11 @@ public abstract class UIBaseManager : MonoBehaviour, ManagerInterface if (Instance == null) { Instance = this; - } else + } + else { + Debug.Log(gameObject); + Debug.Log(Instance); Destroy(gameObject); } } @@ -53,34 +56,27 @@ public abstract class UIBaseManager : MonoBehaviour, ManagerInterface //DynamicPanel = dynamicPanelController; } - public bool OpenPanel() + public virtual bool OpenPanel() { Console.WriteLine("Panel opened"); - //try - //{ - GameObject globalGUI = GameObject.FindGameObjectWithTag("GUI"); + GameObject globalGUI = GameObject.FindGameObjectWithTag("GUI"); - if(!globalGUI) - throw new Exception("Panel could not be opened - can't find global GUI object!!"); - - GameObject uiPanelTemplate = GetTemplatePanel(); + if(!globalGUI) + throw new Exception("Panel could not be opened - can't find global GUI object!!"); + + GameObject uiPanelTemplate = GetTemplatePanel(); - //GameObject.Instantiate(muzzleFlashPrefab, transform.position, transform.rotation); + DynamicPanel = GameObject.Instantiate(uiPanelTemplate, uiPanelTemplate.transform.position, Quaternion.identity, globalGUI.transform); // 4'th arg allow set object as child - DynamicPanel = GameObject.Instantiate(uiPanelTemplate, uiPanelTemplate.transform.position, Quaternion.identity, globalGUI.transform); // 4'th arg allow set object as child - - DynamicPanel.transform.localPosition = uiPanelTemplate.transform.position; // prevent overwritten position by... environment??? + DynamicPanel.transform.localPosition = uiPanelTemplate.transform.position; // prevent overwritten position by... environment??? SetupPanel(); - return true; - //} catch (Exception ex) { Debug.LogError(ex.Message); } - - return false; + return true; } - public bool ClosePanel() + public virtual bool ClosePanel() { Console.WriteLine("Panel closed"); @@ -165,9 +161,4 @@ public abstract class UIBaseManager : MonoBehaviour, ManagerInterface /// /// protected abstract GameObject GetTemplatePanel(); - -/* public T Find(string itemName) - { - throw new NotImplementedException(); - }*/ } diff --git a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIWarehouseManager.cs b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIWarehouseManager.cs index 9775980b..8f390bbd 100644 --- a/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIWarehouseManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Shared/Manager/UI/UIWarehouseManager.cs @@ -7,21 +7,10 @@ public abstract class UIWarehouseManager : UIBaseManager { public virtual int SLOTS_NUMBER => 0; - public static new UIWarehouseManager Instance { get; private set; } + public static new UIWarehouseManager Instance { get; protected set; } /* * not sure why but childrens of this class dont interfere on parents Awake */ - public void Awake() - { - if (Instance == null) - { - Instance = this; - } - else - { - Destroy(gameObject); - } - } /// /// Function to find item in warehouser by its id, returns list of all slots where item occured @@ -49,8 +38,9 @@ public abstract class UIWarehouseManager : UIBaseManager /// Function (SetItemOnPosition) to add slot with its number and item to list (which will be mapped with panel content) /// /// - public void Add(KeyValuePair itemOnSlot) + public virtual void Add(KeyValuePair itemOnSlot) { + if (!CheckIfSlotIsInRange(itemOnSlot.Key)) throw new System.Exception($"Slot number: {itemOnSlot.Key} is out of range, avaiable: {SLOTS_NUMBER} slots"); @@ -59,7 +49,6 @@ public abstract class UIWarehouseManager : UIBaseManager if(itemOnSlot.Value != null) { - Debug.Log($" Added {itemOnSlot.Value} on position {itemOnSlot.Key}"); base.Add(itemOnSlot); } } @@ -68,7 +57,7 @@ public abstract class UIWarehouseManager : UIBaseManager /// Function to add item on first empty slot to list (which will be mapped with panel content) /// /// - public void Add(Item item) + public virtual void Add(Item item) { if(IsFull()) throw new System.Exception($"Warehouse is full!!!"); @@ -81,7 +70,7 @@ public abstract class UIWarehouseManager : UIBaseManager - public void RemoveByPosition(int keyPosition) + public virtual void RemoveByPosition(int keyPosition) { if (!CheckIfSlotExists(keyPosition)) return; // throw new System.Exception($"Slot with number: {keyPosition} don't exist"); @@ -91,16 +80,20 @@ public abstract class UIWarehouseManager : UIBaseManager Elements.RemoveAll(itemSlot => itemSlot.Key == keyPosition); } - public int RemoveByItemId(int itemId) + public virtual int RemoveByItemId(int itemId) { return Elements.RemoveAll(itemSlot => itemSlot.Value.Id == itemId); } - public int RemoveByItemName(string itemName) + public virtual int RemoveByItemName(string itemName) { return Elements.RemoveAll(itemSlot => itemSlot.Value.Name == itemName); } + public virtual void RemoveAll() + { + Elements.Clear(); + } public bool IsFull() { diff --git a/Assets/Prefarbs/Chest.meta b/Assets/Scripts/REFACTORING/Application/UI/Chest.meta similarity index 77% rename from Assets/Prefarbs/Chest.meta rename to Assets/Scripts/REFACTORING/Application/UI/Chest.meta index 707b6c8b..aa15e259 100644 --- a/Assets/Prefarbs/Chest.meta +++ b/Assets/Scripts/REFACTORING/Application/UI/Chest.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 09dff9a30bb15e24492815f4b548638f +guid: c2dc097533c72c34aada9077f5b81301 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestContentUIManager.cs b/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestContentUIManager.cs new file mode 100644 index 00000000..449b2d7b --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestContentUIManager.cs @@ -0,0 +1,112 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ChestContentUIManager : UIWarehouseManager +{ + public static new ChestContentUIManager Instance { get; protected set; } + + public override int SLOTS_NUMBER { get { return 48; } } + + public const string ITEM_LOCALIZATION = "UiPanels/"; + public const string PANEL_NAME = null; + + public void Awake() + { + if (Instance == null) + { + Instance = this; + } + else + { + Debug.Log(Instance); + Debug.Log("destroiy inventory UI"); + Destroy(gameObject); + } + } + /* + public override void UpdateList() + { + // TODO something like rebuild associated panel content + // depending on which class we use it mayu be Inventory / Chest / Shop Panel Controller + DynamicPanel.GetComponent(); //.Refresh() -- rebuild content + }*/ + + public void Update() + { + // use empty function to override parent Update + // to prevent using Open Panel and Close Panel!!! + // this UI manager mustn't open panel - only manage passed chest content and return updated data + } + + public bool OpenPanel() { return true; } + public bool ClosePanel() { return true; } + protected override GameObject GetTemplatePanel() { throw new System.NotImplementedException(); } + + + public override void SetupPanel() + { + base.SetupPanel(); + Debug.Log(Elements); + // setup models list + DynamicPanel.GetComponent().SetUp(Elements); + } + + public override void UpdateList() + { + DynamicPanel.GetComponent().BuildPanelContent(Elements); + } + + #region adust parent function + public override void Add(KeyValuePair itemOnSlot) + { + base.Add(itemOnSlot); + + UpdateChestContent(); + } + + public override void Add(Item item) + { + base.Add(item); + + UpdateChestContent(); + } + + public override void RemoveByPosition(int keyPosition) + { + base.RemoveByPosition(keyPosition); + + UpdateChestContent(); + } + + public override int RemoveByItemId(int itemId) + { + var result = base.RemoveByItemId(itemId); + + UpdateChestContent(); + + return result; + } + + public override int RemoveByItemName(string itemName) + { + var result = base.RemoveByItemName(itemName); + + UpdateChestContent(); + + return result; + } + + public override void RemoveAll() + { + Elements.Clear(); + + UpdateChestContent(); + } + #endregion + + private void UpdateChestContent() + { + ChestUIManager.Instance.UpdateChestContent(ChestUIManager.Instance.CurrentChestName, Elements); + } +} \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestContentUIManager.cs.meta b/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestContentUIManager.cs.meta new file mode 100644 index 00000000..ed10ed09 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestContentUIManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cccb30d385eff4c468ee907498459813 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestUIManager.cs b/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestUIManager.cs new file mode 100644 index 00000000..31989379 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestUIManager.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +[Serializable] +public class ChestUIManager : UIBaseManager +{ + public new static ChestUIManager Instance { get; private set; } + + public const string ITEM_LOCALIZATION = "UiPanels/"; + public const string PANEL_NAME = "ChestPanel"; + public int SLOTS_NUMBER => 48; + + public string CurrentChestName = null; + + public void Awake() + { + if (Instance == null) + { + Instance = this; + } + else + { + Debug.Log(gameObject); + Debug.Log(Instance); + Destroy(gameObject); + } + } + + public override bool OpenPanel() + { + if (CurrentChestName == null || CurrentChestName == "") + { + Debug.Log($"You re not in collision with any chest"); + + return false; + } + + return base.OpenPanel(); + } + + public override bool ClosePanel() + { + base.ClosePanel(); + + ChestContentUIManager.Instance.DynamicPanel = null; + + return true; + } + + public override void SetupPanel() + { + base.SetupPanel(); + + var chest = FindChestInCollection(CurrentChestName); + if (chest == null) + throw new Exception($"Chest {CurrentChestName} not found"); + + ChestContentUIManager.Instance.SetList(chest.GetContent()); + ChestContentUIManager.Instance.DynamicPanel = DynamicPanel; + ChestContentUIManager.Instance.SetupPanel(); + + // setup models list + //DynamicPanel.GetComponent().SetUp(chest.GetContent()); + } + + public override void UpdateList() + { + if (CurrentChestName == null || CurrentChestName == "") + throw new Exception($"You re not in collision with any chest"); + + + var chest = FindChestInCollection(CurrentChestName); + if (chest == null) + throw new Exception($"Chest {CurrentChestName} not found"); + + ChestContentUIManager.Instance.SetList(chest.GetContent()); + ChestContentUIManager.Instance.DynamicPanel = DynamicPanel; + ChestContentUIManager.Instance.UpdateList(); + + //DynamicPanel.GetComponent().BuildPanelContent(chest.GetContent()); + } + + public void UpdateChestContent(string chestName, List> chestContent) + { + Elements.Where(chest => chest.name == chestName).ToList().ForEach(chest => chest.SetContent(chestContent)); + } + + protected override GameObject GetTemplatePanel() + { + // Resources = default path - Asset/Resources ... .obj + return Resources.Load(ITEM_LOCALIZATION + PANEL_NAME) as GameObject; + } + + private Chest FindChestInCollection(string _chestName) + { + return Elements.Find(chest => chest.Name == _chestName); + } +} \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestUIManager.cs.meta b/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestUIManager.cs.meta new file mode 100644 index 00000000..1690cc5f --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/UI/Chest/ChestUIManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2c41ad0a68f8aff469d175f905bbf89e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs b/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs index 1ae3bf09..a197d337 100644 --- a/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs +++ b/Assets/Scripts/REFACTORING/Application/UI/Inventory/InventoryUIManager.cs @@ -5,17 +5,33 @@ using UnityEngine; [Serializable] public class InventoryUIManager : UIWarehouseManager { + public static new InventoryUIManager Instance { get; protected set; } + public override int SLOTS_NUMBER { get { return 48; } } public const string ITEM_LOCALIZATION = "UiPanels/"; public const string PANEL_NAME = "InventoryPanel"; -/* public override void UpdateList() + public void Awake() { - // TODO something like rebuild associated panel content - // depending on which class we use it mayu be Inventory / Chest / Shop Panel Controller - DynamicPanel.GetComponent(); //.Refresh() -- rebuild content - }*/ + if (Instance == null) + { + Instance = this; + } + else + { + Debug.Log(Instance); + Debug.Log("destroiy inventory UI"); + Destroy(gameObject); + } + } + + /* public override void UpdateList() + { + // TODO something like rebuild associated panel content + // depending on which class we use it mayu be Inventory / Chest / Shop Panel Controller + DynamicPanel.GetComponent(); //.Refresh() -- rebuild content + }*/ public override void SetupPanel() { diff --git a/Assets/Scripts/REFACTORING/Application/UI/Panel/ChestPanelController.cs b/Assets/Scripts/REFACTORING/Application/UI/Panel/ChestPanelController.cs new file mode 100644 index 00000000..52dd355a --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/UI/Panel/ChestPanelController.cs @@ -0,0 +1,91 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using System; + + +public class ChestPanelController : WarehousePanelController +{ + protected override UIBaseManager> FetchUiManager() + { + return GameObject.FindObjectOfType(); + } + + // build panel sunction + // - setup - main function to build panel on screen + // - setPanelISlots - build slots on panel dependiong on declared amount + // - setPanelItems - invoking building items on slots + + // api for drag and drop + // - set item on position + // - remove item from position + // - find item in warehouse + + + // 1. Prepare empty panel + public override void BuildPanelSlots() + { + if (_panelContent == null) + throw new Exception("Panel content is not attaches"); + + + for (int _position = 0; _position < UiManager.SLOTS_NUMBER; _position++) + { + //ISlot newSlot = SetupSlot(_position, _panel); + GameObject newSlot = BuildSlot(_position, _panelContent); + + // Set new Slot instance + ChildBoxList.Add(newSlot.GetComponent()); + + // Assign events + ChildBoxList[_position] = SetupDragAndDropToSlot(ChildBoxList[_position]); + } + } + + public override GameObject BuildSlot(int key, GameObject _parent) + { + if (ChildBoxTemplate == null) + throw new Exception("chestslotbox_template is empty"); + + GameObject _newItemSlot = MonoBehaviour.Instantiate(ChildBoxTemplate, _parent.transform.position, Quaternion.identity); //.GetComponent(); + + _newItemSlot.transform.SetParent(_parent.transform); + _newItemSlot.transform.localScale = new Vector3(1.15f, 1.15f, 1.15f); + + _newItemSlot.GetComponent().SetupSlot(key, null, this); + + return _newItemSlot; + } + + + // 2. Set up panel additn items to it + public override void SetUp(List> elements) + { + // Build panel content template + BuildPanelSlots(); + + // Fill with items + BuildPanelContent(elements); + } + + + public override void BuildPanelContent(List> elements) + { + + base.BuildPanelContent(elements); + + Debug.Log("Build content"); + foreach (KeyValuePair element in elements) + { + Debug.Log($"key: {element.Key} - value: {element.Value}"); + ChildBoxList[element.Key].SetItem(new EquippableItem(element.Value)); + } + } +} + + +//Chest content manager +// gest new elements list after open chest +// remove: -> remove from list, (binding) update list in chest \ No newline at end of file diff --git a/Assets/Scripts/Chest/ChestPanelController.cs.meta b/Assets/Scripts/REFACTORING/Application/UI/Panel/ChestPanelController.cs.meta similarity index 83% rename from Assets/Scripts/Chest/ChestPanelController.cs.meta rename to Assets/Scripts/REFACTORING/Application/UI/Panel/ChestPanelController.cs.meta index 2ac7bac0..cba97df8 100644 --- a/Assets/Scripts/Chest/ChestPanelController.cs.meta +++ b/Assets/Scripts/REFACTORING/Application/UI/Panel/ChestPanelController.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8d9e1061a8038f54a87269aa0bd2db04 +guid: 84da00f00bb500c46b1e5629ca4a61b8 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs b/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs index 8ee03b2d..e57535ce 100644 --- a/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs +++ b/Assets/Scripts/REFACTORING/Application/UI/Panel/InventoryPanelController.cs @@ -85,7 +85,7 @@ public class InventoryPanelController : WarehousePanelController foreach (KeyValuePair element in elements) { Debug.Log($"key: {element.Key} - value: {element.Value}"); - ChildBoxList[element.Key].SetItem(element.Value); + ChildBoxList[element.Key].SetItem((EquippableItem)element.Value); } } } diff --git a/Assets/Scripts/REFACTORING/Domain/Enum/ChestTypeEnum.cs b/Assets/Scripts/REFACTORING/Domain/Enum/ChestTypeEnum.cs new file mode 100644 index 00000000..8974fba6 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Domain/Enum/ChestTypeEnum.cs @@ -0,0 +1,10 @@ + +[System.Serializable] +public enum ChestTypeEnum +{ + Wodden, + Silver, + Golden, + Prize, + Extra +} diff --git a/Assets/Scripts/REFACTORING/Domain/Enum/ChestTypeEnum.cs.meta b/Assets/Scripts/REFACTORING/Domain/Enum/ChestTypeEnum.cs.meta new file mode 100644 index 00000000..db0630e7 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Domain/Enum/ChestTypeEnum.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cd359d664589b8c49ad7de7691e39268 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models.meta b/Assets/Scripts/REFACTORING/Models.meta new file mode 100644 index 00000000..74c6914e --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8f774df0851945f084c9d38c173b3a19 +timeCreated: 1660483048 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Models/Chest.meta b/Assets/Scripts/REFACTORING/Models/Chest.meta new file mode 100644 index 00000000..0ec29649 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Chest.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 53cee1e0962a03b47bec40a58b3323c7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Chest/Chest.cs b/Assets/Scripts/REFACTORING/Models/Chest/Chest.cs new file mode 100644 index 00000000..7a2631a7 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Chest/Chest.cs @@ -0,0 +1,106 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +[System.Serializable] +public struct IndexValuePair +{ + [SerializeField] public int Key; + [SerializeField] public T Value; + + public IndexValuePair(int key, T value) + { + Key = key; + Value = value; + } +} + +[System.Serializable] +[CreateAssetMenu(fileName = "New Chest", menuName = "Inventory/Chest")] +public class Chest +{ + public int id; + public int Id + { + get { return id; } + set { id = value; } + } + + public string name; + public string Name + { + get { return name; } + set { name = value; } + } + + public string description; + public string Description + { + get { return description; } + set { description = value; } + } + + public GameObject chestModel; + public GameObject ChestModel + { + get { return chestModel; } + set { chestModel = value; } + } + + public ChestTypeEnum ChestType; + + public List> Content = new List>(); + + + public Chest() { } + + public Chest(Chest _chest) + { + this.Name = _chest.Name; + this.Description = _chest.Description; + this.ChestModel = _chest.ChestModel; + this.ChestType = _chest.ChestType; + this.Content = _chest.Content; + } + + public Chest(string _name, string _description, GameObject _chestModel, ChestTypeEnum _type) + { + this.Name = _name; + this.Description = _description; + this.ChestModel = _chestModel; + this.ChestType = _type; + } + + public Chest(string _name, string _description, GameObject _chestModel, ChestTypeEnum _type, List> _content) + { + this.Name = _name; + this.Description = _description; + this.ChestModel = _chestModel; + this.ChestType = _type; + + SetContent(_content); + } + + public void SetContent(List> _content) + { + Content.Clear(); + + foreach (KeyValuePair element in _content) + { + Content.Add(new IndexValuePair(element.Key, element.Value)); + } + } + + public List> GetContent() + { + List> castedContent = new List>(); + + foreach (IndexValuePair element in Content) + { + castedContent.Add(new KeyValuePair(element.Key, element.Value)); + } + + return castedContent; + } +} diff --git a/Assets/Scripts/REFACTORING/Models/Chest/Chest.cs.meta b/Assets/Scripts/REFACTORING/Models/Chest/Chest.cs.meta new file mode 100644 index 00000000..cd865790 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Chest/Chest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1beed527863993a49ad7bc2695363b77 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Chest/ChestData.cs b/Assets/Scripts/REFACTORING/Models/Chest/ChestData.cs new file mode 100644 index 00000000..9b15fe81 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Chest/ChestData.cs @@ -0,0 +1,64 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +[System.Serializable] +public class ChestData : ModelData +{ + [SerializeField] + public string description; + + [SerializeField] + public ChestTypeEnum type; + + [SerializeField] + public List> content = new List>(); + + + protected override string SPRITE_LOCALIZATION => "Sprites/Object Sprites/"; + protected override string MODEL_LOCALIZATION => "Chests/"; + + public ChestData(Chest chest) : base(chest.id, chest.name, chest.chestModel.name) + { + description = chest.description; + + foreach(IndexValuePair item in chest.Content) + { + content.Add( + new IndexValuePair(item.Key, new EquippableItemData(item.Value)) + ); + } + } + + // dont use parameter - chest is not scriptable object, dont have its model in Assets + public override Chest MapDataToObject() + { + // 1. Find object + GameObject chestGameObject = TryFindResource(modelName); + + var chest = new Chest(name, description, chestGameObject, type); + + // 2. Set chest content from passed data + chest.Content.Clear(); + foreach (IndexValuePair item in content) + { + chest.Content.Add( + new IndexValuePair(item.Key, item.Value.MapDataToObject()) + ); + } + + return chest; + } + + public override Chest MapDataToObject(string prefarbAssetName) { throw new System.NotImplementedException(); } + + protected override GameObject TryFindResource(string modelName) + { + var resource = Resources.Load(MODEL_LOCALIZATION + modelName); + + if (!resource) + throw new System.Exception($"Resource {modelName} not found!!"); + + return resource; + } +} diff --git a/Assets/Scripts/REFACTORING/Models/Chest/ChestData.cs.meta b/Assets/Scripts/REFACTORING/Models/Chest/ChestData.cs.meta new file mode 100644 index 00000000..00516f35 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Chest/ChestData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1e77c35948bf74045bc9f3b32c51e600 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAsset.cs b/Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAsset.cs new file mode 100644 index 00000000..57a26196 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAsset.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +[System.Serializable] +public class ChestPrefabAsset : PrefabAssetModel +{ + + [SerializeField] + public Chest Chest = null; + + //public List> Content { get; set; } + + public ChestPrefabAsset(Chest _chest) + : base(_chest.name, _chest.ChestModel.name, new Vector3(0,0,0)) + { + Chest = _chest; + } + public ChestPrefabAsset(string _name, string _prefabAssetName, Vector3 _position, Chest _chest = null) + : base(_name, _prefabAssetName, _position) + { + Chest = _chest; + } + + public ChestPrefabAssetData MapPrefabAssetModelToData() + { + return new ChestPrefabAssetData(this); + } +} diff --git a/Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAsset.cs.meta b/Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAsset.cs.meta new file mode 100644 index 00000000..e28db445 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAsset.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8516b788b4bb41941946e38c14fec84b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAssetData.cs b/Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAssetData.cs new file mode 100644 index 00000000..69e34745 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAssetData.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using UnityEngine; + +[System.Serializable] +public class ChestPrefabAssetData : PrefabAssetModelData +{ + [SerializeField] ChestData ChestData; + //public List> Content { get; set; } + + public ChestPrefabAssetData(ChestPrefabAsset assetModel) : base(assetModel) + { + ChestData = MapModelToData(assetModel.Chest); + +/* Content = new List>(); + + Debug.Log("ChestPrefarbAsset to ChestPrefarbAssetData - " + assetModel.Name); + + foreach(KeyValuePair itemEntry in assetModel.Content) + { + Debug.Log("Slot nr " + itemEntry.Key); + Content[itemEntry.Key] = itemEntry.Value.MapPrefabAssetModelToData(); + }*/ + } + + public ChestData MapModelToData(Chest chest) + { + return new ChestData(chest); + } + + + public override PrefabAssetModelData PrefabAssetModelToData(PrefabAssetModel assetModel) + { + return new ChestPrefabAssetData((ChestPrefabAsset)assetModel); + } + + public override PrefabAssetModel MapDataToPrefabAssetModel() + { + ChestPrefabAsset chestPrefabAsset = new ChestPrefabAsset( + Name, + PrefabAssetName, + new Vector3(Position[0], Position[1], Position[2]) + ); + + // todo convert each item to data + Debug.Log(ChestData); + chestPrefabAsset.Chest = ChestData.MapDataToObject(); + // clear content and set items from data - this will modify Scri-0ptableObject data also in source + //chestPrefabAsset.Chest.Content.Clear(); +/* foreach (IndexValuePair modelData in ChestData.content) + { + var objectFromData = (modelData.Value).MapDataToObject(); + Debug.Log(objectFromData); + chestPrefabAsset.Chest.Content.Add( + new IndexValuePair(modelData.Key, objectFromData) + ); + }*/ + + return chestPrefabAsset; + } +} diff --git a/Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAssetData.cs.meta b/Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAssetData.cs.meta new file mode 100644 index 00000000..4244b065 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Chest/ChestPrefabAssetData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 412950173e7207545a9041550b13b713 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItem.cs b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItem.cs index 0e61f46a..66f229b7 100644 --- a/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItem.cs +++ b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItem.cs @@ -2,14 +2,14 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -[CreateAssetMenu] [System.Serializable] +[CreateAssetMenu(fileName = "New Item", menuName = "Inventory/EquippableItem")] public class EquippableItem : Item { - public int StrengthBonus; - public int AgilityBonus; - public int InteligenceBonus; - public int VitalityBonus; + public int StrengthBonus = 0; + public int AgilityBonus = 0; + public int InteligenceBonus = 0; + public int VitalityBonus = 0; [Space] public bool isStackable = false; @@ -20,7 +20,15 @@ public class EquippableItem : Item public EquippableItem(){} public EquippableItem(Item _item) : base(_item){} - + + public EquippableItem(EquippableItem _item) : base(_item.name, _item.description, _item.level, _item.itemModel, _item.image) + { + StrengthBonus = _item.StrengthBonus; + AgilityBonus = _item.AgilityBonus; + InteligenceBonus = _item.InteligenceBonus; + VitalityBonus = _item.VitalityBonus; + } + public EquippableItem(string _name, string _description, int _level, GameObject _itemModel, Sprite _image) : base(_name, _description, _level, _itemModel, _image) { } } diff --git a/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemData.cs b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemData.cs index 7fedcb3c..7ae83e03 100644 --- a/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemData.cs +++ b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemData.cs @@ -1,25 +1,26 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; -using UnityEditor; [System.Serializable] public class EquippableItemData : ItemData { + [SerializeField] public int strengthBonus; + [SerializeField] public int agilityBonus; + [SerializeField] public int inteligenceBonus; + [SerializeField] public int vitalityBonus; + [SerializeField] public bool isStackable; + [SerializeField] public EquipmentTypeEnum equipmentType; - private const string ITEM_LOCALIZATION = "Assets/Items/"; - public EquippableItemData(EquippableItem equippableItem) : base(equippableItem) { strengthBonus = equippableItem.StrengthBonus; @@ -31,31 +32,14 @@ public class EquippableItemData : ItemData equipmentType = equippableItem.EquipmentType; } - - public EquippableItem MapDataToEquippableItem(string prefarbAssetName) + public EquippableItemData(Item item) : base(item) { - // Find prefarb in Assets/ - //Debug.Log("MapDataToEquippableItem: " + ITEM_LOCALIZATION + prefarbAssetName + ".asset"); - EquippableItem equippableItem = (EquippableItem)AssetDatabase.LoadAssetAtPath(ITEM_LOCALIZATION + prefarbAssetName + ".asset", typeof(EquippableItem)); + strengthBonus = 0; + agilityBonus = 0; + inteligenceBonus = 0; + vitalityBonus = 0; - /// - // DONT OVERWRITE PROPERTIES BECOUSE ITS EDIT MAIN OBJECT IN ASSET/ - /// - - // equippableItem.StrengthBonus = strengthBonus; - // equippableItem.AgilityBonus = agilityBonus; - // equippableItem.InteligenceBonus = inteligenceBonus; - // equippableItem.VitalityBonus = vitalityBonus; - // equippableItem.isStackable = isStackable; - // equippableItem.EquipmentTypeEnum = equipmentType; - - // Item item = base.MapDataToItem(prefarbAssetName); - // equippableItem.Name = item.Name; - // equippableItem.Description = item.Description; - // equippableItem.Level = item.Level; - // equippableItem.ItemModel = item.ItemModel; - // equippableItem.Image = item.Image; - - return equippableItem; + isStackable = true; + equipmentType = EquipmentTypeEnum.Other; } } diff --git a/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAssetData.cs b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAssetData.cs index 0b40d364..d27a6165 100644 --- a/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAssetData.cs +++ b/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemPrefabAssetData.cs @@ -3,11 +3,11 @@ using UnityEngine; [System.Serializable] public class EquippableItemPrefabAssetData : PrefabAssetModelData { - EquippableItemData EquippableItemData; + public EquippableItemData EquippableItemData; public EquippableItemPrefabAssetData(EquippableItemPrefabAsset assetModel) : base(assetModel) { - EquippableItemData = MapEquippableItemToData(assetModel.EquippableItem); + EquippableItemData = MapModelToData(assetModel.EquippableItem); } /// @@ -15,7 +15,7 @@ public class EquippableItemPrefabAssetData : PrefabAssetModelData /// /// /// - public EquippableItemData MapEquippableItemToData(EquippableItem equippableItem) + public EquippableItemData MapModelToData(EquippableItem equippableItem) { return new EquippableItemData(equippableItem); } @@ -38,7 +38,7 @@ public class EquippableItemPrefabAssetData : PrefabAssetModelData new Vector3(Position[0], Position[1], Position[2]) ); - equippableItemPrefabAsset.EquippableItem = EquippableItemData.MapDataToEquippableItem(equippableItemPrefabAsset.PrefabAssetName); + equippableItemPrefabAsset.EquippableItem = (EquippableItem)EquippableItemData.MapDataToObject(equippableItemPrefabAsset.PrefabAssetName); return equippableItemPrefabAsset; } diff --git a/Assets/Scripts/REFACTORING/Models/Item/ItemData.cs b/Assets/Scripts/REFACTORING/Models/Item/ItemData.cs index 62fe57a9..99dafa5a 100644 --- a/Assets/Scripts/REFACTORING/Models/Item/ItemData.cs +++ b/Assets/Scripts/REFACTORING/Models/Item/ItemData.cs @@ -1,57 +1,66 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; -using UnityEditor; + [System.Serializable] -public class ItemData +public abstract class ItemData : ModelData { - public int id; - - public string name; - + [SerializeField] public string description; + [SerializeField] public int level; + [SerializeField] public string imageName; - // to handle object created on scene for example after removing from inventory - public string itemModelName; + protected override string SPRITE_LOCALIZATION => "Sprites/Object Sprites/"; + protected override string MODEL_LOCALIZATION => "Items/"; - private const string SPRITE_LOCALIZATION = "Sprites/Object Sprites/"; - private const string ITEM_LOCALIZATION = "Assets/Items/"; - - public ItemData(Item item) + public ItemData(Item item) : base(item.id, item.name, item.itemModel.name) { - id = item.id; - name = item.name; description = item.description; level = item.level; imageName = item.image.name; - itemModelName = item.itemModel.name; } - public Item MapDataToItem(string prefarbAssetName) + public override Item MapDataToObject(string prefarbAssetName) { - // Find prefarb in Assets/ - Item item = (Item)AssetDatabase.LoadAssetAtPath(ITEM_LOCALIZATION + prefarbAssetName + ".asset", typeof(Item)); + Debug.Log("item prefab from asset name - data to object"); + Debug.Log(MODEL_LOCALIZATION + prefarbAssetName + ".asset"); + + return TryFindResource(prefarbAssetName); /// // DONT OVERWRITE PROPERTIES BECOUSE ITS EDIT MAIN OBJECT IN ASSET/ /// - // item.Id = this.id; - // item.Name = this.name; - // item.Description = this.description; - // item.Level = this.level; + // equippableItem.StrengthBonus = strengthBonus; + // equippableItem.AgilityBonus = agilityBonus; + // equippableItem.InteligenceBonus = inteligenceBonus; + // equippableItem.VitalityBonus = vitalityBonus; + // equippableItem.isStackable = isStackable; + // equippableItem.EquipmentTypeEnum = equipmentType; - // Debug.Log(ITEM_LOCALIZATION + this.imageName); - // item.Image = (Sprite)AssetDatabase.LoadAssetAtPath(ITEM_LOCALIZATION + this.imageName, typeof(Sprite)); - // Debug.Log(item.Image); - - // item.ItemModel = (GameObject)AssetDatabase.LoadAssetAtPath(ITEM_LOCALIZATION + "Gold Ore" + ".prefab", typeof(GameObject)); - - return item; + // Item item = base.MapDataToItem(prefarbAssetName); + // equippableItem.Name = item.Name; + // equippableItem.Description = item.Description; + // equippableItem.Level = item.Level; + // equippableItem.ItemModel = item.ItemModel; + // equippableItem.Image = item.Image; } -} \ No newline at end of file + + public override Item MapDataToObject() + { + return TryFindResource(modelName); + } + + protected override Item TryFindResource(string modelName) + { + var resource = Resources.Load(MODEL_LOCALIZATION + modelName); + Debug.Log(MODEL_LOCALIZATION + modelName); + if (!resource) + throw new System.Exception($"Resource {modelName} not found!!"); + + return resource; + } +} diff --git a/Assets/Scripts/Chest/ChestSlot.cs b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ChestSlot.cs similarity index 83% rename from Assets/Scripts/Chest/ChestSlot.cs rename to Assets/Scripts/REFACTORING/Models/Panel/Slot/ChestSlot.cs index b3fab047..1b9a1304 100644 --- a/Assets/Scripts/Chest/ChestSlot.cs +++ b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ChestSlot.cs @@ -1,9 +1,15 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.EventSystems; public class ChestSlot : ItemSlot { +/* public ChestSlot(int number, Item item): base(number, item) + { + + }*/ + public override bool CanReceiveItem(Item item) { return true; diff --git a/Assets/Scripts/Chest/ChestSlot.cs.meta b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ChestSlot.cs.meta similarity index 100% rename from Assets/Scripts/Chest/ChestSlot.cs.meta rename to Assets/Scripts/REFACTORING/Models/Panel/Slot/ChestSlot.cs.meta diff --git a/Assets/Scripts/REFACTORING/Models/Panel/Slot/ISlot.cs b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ISlot.cs index 24f4ad15..21181fa8 100644 --- a/Assets/Scripts/REFACTORING/Models/Panel/Slot/ISlot.cs +++ b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ISlot.cs @@ -8,7 +8,7 @@ using System; public interface ISlot { int Number { get; set; } - Item Item { get; set; } + EquippableItem Item { get; set; } // enum typ dziecka // A : enum A @@ -19,7 +19,7 @@ public interface ISlot event Action OnDropEvent; //(B)Islot // as B - public void SetupSlot(int _number, Item _item, WarehousePanelController _PanelController); - public void SetItem(Item _item); + public void SetupSlot(int _number, EquippableItem _item, WarehousePanelController _PanelController); + public void SetItem(EquippableItem _item); bool CanReceiveItem(Item item); } \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Models/Panel/Slot/InventorySlot.cs b/Assets/Scripts/REFACTORING/Models/Panel/Slot/InventorySlot.cs index 7ff24883..82e5438c 100644 --- a/Assets/Scripts/REFACTORING/Models/Panel/Slot/InventorySlot.cs +++ b/Assets/Scripts/REFACTORING/Models/Panel/Slot/InventorySlot.cs @@ -4,6 +4,11 @@ using UnityEngine; public class InventorySlot : ItemSlot { +/* public InventorySlot(int number, Item item) : base(number, item) + { + + }*/ + public override bool CanReceiveItem(Item item) { return true; diff --git a/Assets/Scripts/REFACTORING/Models/Panel/Slot/ItemSlot.cs b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ItemSlot.cs index 8f357e6c..50508c05 100644 --- a/Assets/Scripts/REFACTORING/Models/Panel/Slot/ItemSlot.cs +++ b/Assets/Scripts/REFACTORING/Models/Panel/Slot/ItemSlot.cs @@ -27,8 +27,8 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler } } [SerializeField] - protected Item _item; - public Item Item { + protected EquippableItem _item; + public EquippableItem Item { get { return _item; } set { _item = value; @@ -48,7 +48,23 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler public event Action OnDragEvent; public event Action OnDropEvent; - public void SetupSlot(int _number, Item _item, WarehousePanelController _PanelController) +/* public ItemSlot() { } + public ItemSlot(int number, EquippableItem item = null) + { + Number = number; + Item = item; + }*/ +/* + public ItemSlot(ItemSlot slot) + { + Number = slot.Number; + Item = slot.Item; + + slotItemNumberText = slot.slotItemNumberText; + itemImage = slot.itemImage; + }*/ + + public void SetupSlot(int _number, EquippableItem _item, WarehousePanelController _PanelController) { this._PanelController = _PanelController; @@ -60,7 +76,7 @@ public class ItemSlot : MonoBehaviour, ISlot, IBeginDragHandler, IEndDragHandler } } - public void SetItem(Item _item) // dont change slot numer after assign new item, numbers are bind during object init + public void SetItem(EquippableItem _item) // dont change slot numer after assign new item, numbers are bind during object init { Item = _item; diff --git a/Assets/Scripts/REFACTORING/Models/Scene.meta b/Assets/Scripts/REFACTORING/Models/Scene.meta deleted file mode 100644 index cdd3ac0d..00000000 --- a/Assets/Scripts/REFACTORING/Models/Scene.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 08674bb7d06248b8b6174ac07b325ee7 -timeCreated: 1662917411 \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Models/Shared/ModelData.cs b/Assets/Scripts/REFACTORING/Models/Shared/ModelData.cs new file mode 100644 index 00000000..05967ee0 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Shared/ModelData.cs @@ -0,0 +1,39 @@ +using System.Collections; +using UnityEngine; + +[System.Serializable] +public abstract class ModelData +{ + [SerializeField] + public int id; + + [SerializeField] + public string name; + + // to handle object created on scene for example after removing from inventory + [SerializeField] + public string modelName; + + protected virtual string SPRITE_LOCALIZATION => ""; + + protected virtual string MODEL_LOCALIZATION => ""; + + public ModelData(int _id, string _name) + { + id = _id; + name = _name; + } + + public ModelData(int _id, string _name, string _modelName) + { + id = _id; + name = _name; + modelName = _modelName; // name of the prefab + } + + public abstract T MapDataToObject(string prefarbAssetName); + + public abstract T MapDataToObject(); + + protected abstract V TryFindResource(string modelName); +} \ No newline at end of file diff --git a/Assets/Scripts/REFACTORING/Models/Shared/ModelData.cs.meta b/Assets/Scripts/REFACTORING/Models/Shared/ModelData.cs.meta new file mode 100644 index 00000000..cafa5b99 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Models/Shared/ModelData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5898041170649a94fa3172f2291ec24a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModelData.cs b/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModelData.cs index 482e292d..3a3cd7e9 100644 --- a/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModelData.cs +++ b/Assets/Scripts/REFACTORING/Models/Shared/PrefabAssetModelData.cs @@ -2,13 +2,13 @@ using System; using UnityEngine; [Serializable] -public abstract class PrefabAssetModelData +public class PrefabAssetModelData { - [SerializeField] public string Name { get; set; } + [SerializeField] public string Name; - [SerializeField] public string PrefabAssetName { get; set; } + [SerializeField] public string PrefabAssetName; - [SerializeField] public float[] Position { get; set; } + [SerializeField] public float[] Position; public PrefabAssetModelData(PrefabAssetModel assetModel) @@ -22,7 +22,17 @@ public abstract class PrefabAssetModelData Position[2] = assetModel.Position.z; } - public abstract PrefabAssetModelData PrefabAssetModelToData(PrefabAssetModel assetModel); + public virtual PrefabAssetModelData PrefabAssetModelToData(PrefabAssetModel assetModel) + { + return new PrefabAssetModelData(assetModel); + } - public abstract PrefabAssetModel MapDataToPrefabAssetModel(); + public virtual PrefabAssetModel MapDataToPrefabAssetModel() + { + return new PrefabAssetModel( + Name, + PrefabAssetName, + new Vector3(Position[0], Position[1], Position[2]) + ); + } } diff --git a/Assets/Scripts/SceneManager/SaveChest.meta b/Assets/Scripts/SceneManager/SaveChest.meta deleted file mode 100644 index 49702783..00000000 --- a/Assets/Scripts/SceneManager/SaveChest.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5edd9215206d6134ca9e51265abeb679 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/SceneManager/SaveChest/ChestData.meta b/Assets/Scripts/SceneManager/SaveChest/ChestData.meta deleted file mode 100644 index 437bd713..00000000 --- a/Assets/Scripts/SceneManager/SaveChest/ChestData.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: a10cc331a77b9af4aad20839724f2370 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAsset.cs b/Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAsset.cs deleted file mode 100644 index cb9167a1..00000000 --- a/Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAsset.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -[System.Serializable] -public class ChestPrefarbAsset -{ - [SerializeField] - public string name; - [SerializeField] - public string prefarbAssetName; - [SerializeField] - public Vector3 position; - [SerializeField] - public Dictionary content = new Dictionary(); - - public ChestPrefarbAsset() {} - - public ChestPrefarbAsset(string _name, string _prefarbAssetName, Vector3 _position, Dictionary _content) - { - name = _name; - prefarbAssetName = _prefarbAssetName; - position = _position; - content = _content; - } -} diff --git a/Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAssetData.cs b/Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAssetData.cs deleted file mode 100644 index 18b65431..00000000 --- a/Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAssetData.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using System.Linq; - -[System.Serializable] -public class ChestPrefarbAssetData -{ - public string name; - - public string prefarbAssetName; - - public float[] position; - - public Dictionary content = new Dictionary(); - - public ChestPrefarbAssetData(ChestPrefarbAsset chestPrefarbAsset) - { - name = chestPrefarbAsset.name; - prefarbAssetName = chestPrefarbAsset.prefarbAssetName; - - position = new float[3]; - position[0] = chestPrefarbAsset.position.x; - position[1] = chestPrefarbAsset.position.y; - position[2] = chestPrefarbAsset.position.z; - - Debug.Log("ChestPrefarbAsset to ChestPrefarbAssetData - " + chestPrefarbAsset.name); - foreach(KeyValuePair itemEntry in chestPrefarbAsset.content) - { - Debug.Log("Slot nr " + itemEntry.Key); - this.content[itemEntry.Key] = this.EquippableItemPrefarbAssetToData(itemEntry.Value); - } - } - - public EquippableItemPrefarbAssetData EquippableItemPrefarbAssetToData(EquippableItemPrefarbAsset equippableItemPrefarbAsset) - { - return new EquippableItemPrefarbAssetData(equippableItemPrefarbAsset); - } - - public ChestPrefarbAsset MapDataToChestPrefarbAsset() - { - ChestPrefarbAsset chestPrefarbAsset = new ChestPrefarbAsset(); - chestPrefarbAsset.name = this.name; - chestPrefarbAsset.prefarbAssetName = this.prefarbAssetName; - chestPrefarbAsset.position = new Vector3(this.position[0], this.position[1], this.position[2]); - - foreach(KeyValuePair equippableItemPrefarbAssetDataEntry in this.content) - { - chestPrefarbAsset.content[equippableItemPrefarbAssetDataEntry.Key] = equippableItemPrefarbAssetDataEntry.Value.MapDataToEquippableItemPrefarbAsset(); - } - - return chestPrefarbAsset; - } -} diff --git a/Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAssetData.cs.meta b/Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAssetData.cs.meta deleted file mode 100644 index d687df20..00000000 --- a/Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAssetData.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9a58ed5e0b9d76143be15d0f7a9d67ce -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/SceneManager/SaveChest/SaveChestSystem.cs b/Assets/Scripts/SceneManager/SaveChest/SaveChestSystem.cs deleted file mode 100644 index f09159b9..00000000 --- a/Assets/Scripts/SceneManager/SaveChest/SaveChestSystem.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using System.IO; -using System.Runtime.Serialization.Formatters.Binary; - -public static class SaveChestSystem -{ - private static string map; - -public static void SaveChest(ChestPrefarbAsset chestPrefarbAsset, string ElementFolderName) - { - BinaryFormatter formatter = new BinaryFormatter(); - // todo: add in scene name folder - string path = SaveSystem.GetSavePath(ElementFolderName); -Debug.Log(path); - if (!Directory.Exists(path)) - Directory.CreateDirectory(path); - - path += "/" + chestPrefarbAsset.name + ".fun"; - - FileStream stream = new FileStream(path, FileMode.Create); - - ChestPrefarbAssetData chestData = new ChestPrefarbAssetData(chestPrefarbAsset); - - formatter.Serialize(stream, chestData); - stream.Close(); - } - - public static void SaveChestsList(List chestPrefarbAssetList, string _path, string ElementName) - { - BinaryFormatter formatter = new BinaryFormatter(); - // todo: add in scene name folder - string path = SaveSystem.GetSavePath(_path); -Debug.Log("Saved Chest at " + path); - if (!Directory.Exists(path)) - Directory.CreateDirectory(path); - - path += "/" + ElementName + ".fun"; - - FileStream stream = new FileStream(path, FileMode.Create); - - List chestsListData = new List(); - - Debug.Log("---- Save Chest"); - - foreach(ChestPrefarbAsset chest in chestPrefarbAssetList) - { - Debug.Log(chest.name); - Debug.Log(chest.content.Count); - foreach(KeyValuePair equippableItemPrefarbAsset in chest.content) - { - Debug.Log("item on position " + equippableItemPrefarbAsset.Key + " " + equippableItemPrefarbAsset.Value.equippableItem.name); - } - chestsListData.Add(new ChestPrefarbAssetData(chest)); - } - - formatter.Serialize(stream, chestsListData); - stream.Close(); - } - - private static void Save() - { - - } - - public static ChestPrefarbAssetData LoadChest(string chestName, string ElementFolderName) - { - string path = SaveSystem.GetSavePath(ElementFolderName) + "/" + chestName;// + ".fun"; - - if(File.Exists(path)) - { - BinaryFormatter formatter = new BinaryFormatter(); - FileStream stream = new FileStream(path, FileMode.Open); - - ChestPrefarbAssetData chestData = formatter.Deserialize(stream) as ChestPrefarbAssetData; - stream.Close(); - - return chestData; - } else { - Debug.Log("Save file not found in " + path); - return null; - } - } - - public static List LoadChestsList(string _path, string ElementName) - { - string path = SaveSystem.GetSavePath(_path) + "/" + ElementName + ".fun"; - - if(File.Exists(path)) - { - - BinaryFormatter formatter = new BinaryFormatter(); - FileStream stream = new FileStream(path, FileMode.Open); - - List chestsListData = formatter.Deserialize(stream) as List; - stream.Close(); - - return chestsListData; - } else { - Debug.Log("Save file not found in " + path); - return null; - } - } -} diff --git a/Assets/Scripts/SceneManager/SaveChest/SaveChestSystem.cs.meta b/Assets/Scripts/SceneManager/SaveChest/SaveChestSystem.cs.meta deleted file mode 100644 index 14213cb9..00000000 --- a/Assets/Scripts/SceneManager/SaveChest/SaveChestSystem.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b3dae3c259ff42a4d8ee3f1d82fb02c5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/SceneManager/SceneChestManager.cs b/Assets/Scripts/SceneManager/SceneChestManager.cs deleted file mode 100644 index 332170cd..00000000 --- a/Assets/Scripts/SceneManager/SceneChestManager.cs +++ /dev/null @@ -1,273 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEditor; -using UnityEngine.SceneManagement; -using System.IO; -using System.Linq; - -// only for eqipptable items -public class SceneChestManager : MonoBehaviour -{ - private const string GameObjectLocalization = "Assets/Items/Chest/"; // for prefarb - - private const string AssetLocalization = "Assets/Items/"; // for Equitabble asset - - //private const string DYNAMIC_ELEMENT = "/DynamicElements/"; - private const string STATIC_ELEMENT = "/StaticElements/"; - - // content skrzyni (docelowo skrzynia + jej content) - - /// - /// Handle manually setuped object properties - /// eg. npc, minions, chest content - /// - [SerializeField] - public List StaticElements; - - /// - /// Handle dynamic object properties - /// eg. dropped items - /// - // PrefarbAsset - [SerializeField] - public List DynamicElements; - - public bool isNewGame = true; - public bool isContinued = false; - public string MapName; - public string ElementFolderName = "Chest"; - public string ItemsListName = "ChestList"; - - public static SceneChestManager Instance; - - public void Awake() - { - if(Instance == null) - { - this.MapName = SceneManager.GetActiveScene().name; - - if(isNewGame) // in new game dynamicItemsList is defaulty empty - { - //BuildChests(StaticElements); - - }else if(isContinued) - { - //LoadChests(); - - //BuildChests(DynamicElements); - } - - Instance = this; - - - }else if (Instance != this) - { - Destroy(gameObject); - } - - - } - - public void Start() - { - // EXAMPLE HOW TO ADD ELEMENTS TO CHEST - // - // this.StaticElements.Add( - // new ChestPrefarbAsset("test chest", "Wooden Chest", new Vector3(0, 0, 0), - // new Dictionary{ - // {1, new EquippableItemPrefarbAsset("Pickaxe test", "Pickaxe", new Vector3(0,0,0), "Pickaxe")}, - // {4, new EquippableItemPrefarbAsset("Gold ore test", "Gold Ore", new Vector3(0,0,0), "Gold Ore")}, - // }) - // ); - - LoadChests(); - BuildChests(StaticElements); - - } - - public int AddItemToChest(string chestName, int keyPosition, EquippableItem addedItem){ - - // 1. Find Chest in List and update value - this.StaticElements.Where(chestPrefarbAsset => chestPrefarbAsset.name == chestName).ToList().ForEach(chest => { - chest.content[keyPosition] = new EquippableItemPrefarbAsset(addedItem.name, addedItem.name, new Vector3(0,0,0), addedItem); - Debug.Log("Added element " + addedItem.name + " to chest (" + chestName + ")"); - }); - - return keyPosition; - } - - public void RemoveItemFromChest(string chestName, int keyPosition) - { - // 1. Find Chest in List - baically ther should be one chest with this name but who know :D - this.StaticElements.Where(chestPrefarbAsset => chestPrefarbAsset.name == chestName).ToList().ForEach(chest => { - chest.content.Remove(keyPosition); - Debug.Log("Removed element on position -" + keyPosition + " - from chest (" + chestName + ")"); - }); - } - - // public void RemoveDynamicEquippableItem(EquippableItemPrefarbAsset equippableItemPrefarbAsset) - // { - // } - - public void BuildChests(List chestPrefarbAssetList) - { - foreach(ChestPrefarbAsset chestPrefarbAsset in chestPrefarbAssetList) - { - - GameObject newChestObject = (GameObject)AssetDatabase.LoadAssetAtPath(GameObjectLocalization + chestPrefarbAsset.prefarbAssetName + ".prefab", typeof(GameObject)); - - if(!newChestObject) - { - Debug.Log("Can't find prefarb by name " + chestPrefarbAsset.prefarbAssetName); - break; - } - - - GameObject globalGUI = GameObject.FindGameObjectsWithTag("GUI")[0]; - - if(globalGUI) - { - // 1. Create gameObject by handled prefarb - // 2. SetUp - // 2.1 Set position - GameObject chest = Instantiate(newChestObject, chestPrefarbAsset.position, Quaternion.identity, globalGUI.transform); - - // 2.2 Set name - chest.name = chestPrefarbAsset.name; - - //chest.transform.SetParent(globalGUI.transform); - // 2.3 Set pransform - chest.transform.localScale = new Vector3(0.5f, 0.5f, 1); - - // 3. SetUp EqippableItems list - Dictionary itemsOfChestList = chestPrefarbAsset.content; - - string[] assetNames = AssetDatabase.FindAssets("t:EquippableItem", new[] { AssetLocalization }); - - foreach(KeyValuePair itemsOfChestEntry in itemsOfChestList) - { - // 3.1 find object - foreach (string SOName in assetNames) - { - var SOpath = AssetDatabase.GUIDToAssetPath(SOName); - - if(SOpath.Contains(itemsOfChestEntry.Value.prefarbAssetName + ".asset")) - { - // 3.2 set EquippableItem object - chest.GetComponent().SetupItemInChest( - itemsOfChestEntry.Key, - AssetDatabase.LoadAssetAtPath(SOpath) - ); - - break; - } - } - } - - - - - } else { - Debug.Log("Can't find global GUI object!!!"); - break; - } - } - } - - // public void BuildChestItems(Dictionary itemsList) - // { - // // pass to InventoryManager singleton - // foreach(KeyValuePair itemEntry in itemsList) - // InventoryManager.Instance.SetupItemInInventory(itemEntry.Key, itemEntry.Value.equippableItem); - // } - - /// Save both list of EquippableItems - public void SaveChests() - { - // 1. staticElements - this.SaveStaticChestsList(); - } - - #region Static list of EquippableItem Save - private void SaveStaticChestsList() - { - // Case I - if we remember all list - // 1) if after removed item form DynamicList is empty - remove all file - // 2) if after removed item form DynamciList there are another one - save updated list again - if(this.StaticElements.Count > 0) { - SaveChestSystem.SaveChestsList(this.StaticElements, this.MapName + STATIC_ELEMENT, this.ItemsListName); // change to SaveEquippableItemSystem for EquippableItemPrefarbAsset - } else { - string _path = SaveSystem.GetSavePath(this.MapName + STATIC_ELEMENT) + "/" + this.ItemsListName + ".fun"; - - try - { - Debug.Log("File to remove: " + _path); - - if(File.Exists(_path)) - { - File.Delete(_path); - } - } - catch (IOException ioExp) - { - Debug.LogError(ioExp.Message); - } - } - - // Case II - if we rememenber object per file - // 1) remove specyfic file - // - // Unfortunatelly we don't use this way of saving items yet :D - } - #endregion - - public void LoadChests() - { - // if continue -> search files with content in save path - - // if new game -> build objects from default configuration - Debug.Log("Load chest"); - this.LoadStaticChestsList(); - } - - - - #region Static list of Chest Loader - public void LoadStaticChestsList() - { - string path = SaveSystem.GetSavePath(this.MapName + STATIC_ELEMENT); - - if (!Directory.Exists(path)) // if not exists thats mean there was nothing saved yet - nothing to load - return; - - FileInfo[] fileInfo = new DirectoryInfo(path).GetFiles(); - - foreach(FileInfo file in fileInfo) - { - Debug.Log(file.FullName); - - List chestPrefarbAssetList = new List(); - - List chestPrefarbAssetDataList = SaveChestSystem.LoadChestsList(this.MapName + STATIC_ELEMENT, this.ItemsListName); - - foreach(ChestPrefarbAssetData chestPrefarbAssetData in chestPrefarbAssetDataList) - chestPrefarbAssetList.Add(chestPrefarbAssetData.MapDataToChestPrefarbAsset()); - - Debug.Log("---- Load Chest"); - - foreach(ChestPrefarbAsset chest in chestPrefarbAssetList) - { - Debug.Log(chest.name); - foreach(KeyValuePair equippableItemPrefarbAsset in chest.content) - { - // Debug.Log("item on position " + equippableItemPrefarbAsset.Key + - // " " + equippableItemPrefarbAsset.Value.equippableItem.name); - } - } - - this.StaticElements = chestPrefarbAssetList; - } - } - #endregion -} diff --git a/Assets/Scripts/SceneManager/SceneChestManager.cs.meta b/Assets/Scripts/SceneManager/SceneChestManager.cs.meta deleted file mode 100644 index 6b74446e..00000000 --- a/Assets/Scripts/SceneManager/SceneChestManager.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1b522b9a99467e740adc3e2ce6036ebe -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/SceneManager/SceneEquippableItemManager.cs b/Assets/Scripts/SceneManager/SceneEquippableItemManager.cs index a367f279..9a23f8a1 100644 --- a/Assets/Scripts/SceneManager/SceneEquippableItemManager.cs +++ b/Assets/Scripts/SceneManager/SceneEquippableItemManager.cs @@ -23,7 +23,7 @@ public class SceneEquippableItemManager : MonoBehaviour /// eg. npc, minions, chest content /// [SerializeField] - public List StaticElements; + public List StaticElements; /// /// Handle dynamic object properties @@ -31,7 +31,7 @@ public class SceneEquippableItemManager : MonoBehaviour /// // PrefarbAsset [SerializeField] - public List DynamicElements; + public List DynamicElements; public bool isNewGame = true; public bool isContinued = false; @@ -81,14 +81,14 @@ public class SceneEquippableItemManager : MonoBehaviour // public void AddDynamicItem(GameObject object) { // //EquippableItem item = object.GetComponent().Item; - // //EquippableItemPrefarbAsset equippableItemPrefarbAsset = new EquippableItemPrefarbAsset(item.name, object.name, object.transform.position, item); + // //EquippableItemPrefabAsset equippableItemPrefarbAsset = new EquippableItemPrefabAsset(item.name, object.name, object.transform.position, item); // //this.dynamicItems.Add(equippableItemPrefarbAsset); // } public int AddDynamicItem(GameObject dynamicObject) { EquippableItem item = dynamicObject.GetComponent().item; - EquippableItemPrefarbAsset equippableItemPrefarbAsset = new EquippableItemPrefarbAsset(item.name, dynamicObject.name, dynamicObject.transform.position, item); + EquippableItemPrefabAsset equippableItemPrefarbAsset = new EquippableItemPrefabAsset(item.name, dynamicObject.name, dynamicObject.transform.position, item); this.DynamicElements.Add(equippableItemPrefarbAsset); @@ -98,26 +98,26 @@ public class SceneEquippableItemManager : MonoBehaviour public void RemoveDynamicItem(string name) { // 1. Fetch all matched items - List equippableItemPrefarbAssetList = this.DynamicElements.Where(eqItemAss => eqItemAss.name == name).ToList(); + List equippableItemPrefarbAssetList = this.DynamicElements.Where(eqItemAss => eqItemAss.Name == name).ToList(); // 2. Remove them - this.DynamicElements.RemoveAll(eqItemAss => eqItemAss.name == name); + this.DynamicElements.RemoveAll(eqItemAss => eqItemAss.Name == name); } - public void RemoveDynamicEquippableItem(EquippableItemPrefarbAsset equippableItemPrefarbAsset) + public void RemoveDynamicEquippableItem(EquippableItemPrefabAsset equippableItemPrefarbAsset) { } - public void BuildItems(List equippableItemPrefarbAssetList) + public void BuildItems(List equippableItemPrefarbAssetList) { - foreach(EquippableItemPrefarbAsset equippableItemPrefarbAsset in equippableItemPrefarbAssetList) + foreach(EquippableItemPrefabAsset equippableItemPrefarbAsset in equippableItemPrefarbAssetList) { - GameObject newEquippableItemObject = (GameObject)AssetDatabase.LoadAssetAtPath(GameObjectLocalization + equippableItemPrefarbAsset.prefarbAssetName + ".prefab", typeof(GameObject)); + GameObject newEquippableItemObject = (GameObject)AssetDatabase.LoadAssetAtPath(GameObjectLocalization + equippableItemPrefarbAsset.PrefabAssetName + ".prefab", typeof(GameObject)); if(!newEquippableItemObject) { - Debug.Log("Can't find prefarb by name " + equippableItemPrefarbAsset.prefarbAssetName); + Debug.Log("Can't find prefarb by name " + equippableItemPrefarbAsset.PrefabAssetName); break; } @@ -129,10 +129,10 @@ public class SceneEquippableItemManager : MonoBehaviour // 1. Create gameObject by handled prefarb // 2. SetUp // 2.1 Set position - GameObject equippableItem = Instantiate(newEquippableItemObject, equippableItemPrefarbAsset.position, Quaternion.identity, globalGUI.transform); + GameObject equippableItem = Instantiate(newEquippableItemObject, equippableItemPrefarbAsset.Position, Quaternion.identity, globalGUI.transform); // 2.2 Set name - equippableItem.name = equippableItemPrefarbAsset.name; + equippableItem.name = equippableItemPrefarbAsset.Name; equippableItem.transform.SetParent(globalGUI.transform); // 2.3 Set pransform @@ -147,7 +147,7 @@ public class SceneEquippableItemManager : MonoBehaviour { var SOpath = AssetDatabase.GUIDToAssetPath(SOName); - if(SOpath.Contains(equippableItemPrefarbAsset.prefarbAssetName + ".asset")) + if(SOpath.Contains(equippableItemPrefarbAsset.PrefabAssetName + ".asset")) { // 3.2 set EquippableItem object equippableItem.GetComponent().item = AssetDatabase.LoadAssetAtPath(SOpath); @@ -173,9 +173,9 @@ public class SceneEquippableItemManager : MonoBehaviour this.SaveDynamicEquippableItemsList(); /// Load One element example - // foreach(EquippableItemPrefarbAsset equippableItemPrefarbAsset in equippableItemPrefarbAssetList) + // foreach(EquippableItemPrefabAsset equippableItemPrefarbAsset in equippableItemPrefarbAssetList) // { - // SaveEquippableItemSystem.SaveEquitableItem(equippableItemPrefarbAsset, this.MapName + "/" + this.ElementFolderName); // change to SaveEquippableItemSystem for EquippableItemPrefarbAsset + // SaveEquippableItemSystem.SaveEquitableItem(equippableItemPrefarbAsset, this.MapName + "/" + this.ElementFolderName); // change to SaveEquippableItemSystem for EquippableItemPrefabAsset // } } @@ -187,7 +187,7 @@ public class SceneEquippableItemManager : MonoBehaviour // 1) if after removed item form DynamicList is empty - remove all file // 2) if after removed item form DynamciList there are another one - save updated list again if(this.StaticElements.Count > 0) { - SaveEquippableItemSystem.SaveEquitableItemList(this.StaticElements, this.MapName + STATIC_ELEMENT, this.ItemsListName); // change to SaveEquippableItemSystem for EquippableItemPrefarbAsset + SaveEquippableItemSystem.SaveEquitableItemList(this.StaticElements, this.MapName + STATIC_ELEMENT, this.ItemsListName); // change to SaveEquippableItemSystem for EquippableItemPrefabAsset } else { string _path = SaveSystem.GetSavePath(this.MapName + STATIC_ELEMENT) + "/" + this.ItemsListName + ".fun"; @@ -220,7 +220,7 @@ public class SceneEquippableItemManager : MonoBehaviour // 1) if after removed item form DynamicList is empty - remove all file // 2) if after removed item form DynamciList there are another one - save updated list again if(this.DynamicElements.Count > 0) { - SaveEquippableItemSystem.SaveEquitableItemList(this.DynamicElements, this.MapName + DYNAMIC_ELEMENT, this.ItemsListName); // change to SaveEquippableItemSystem for EquippableItemPrefarbAsset + SaveEquippableItemSystem.SaveEquitableItemList(this.DynamicElements, this.MapName + DYNAMIC_ELEMENT, this.ItemsListName); // change to SaveEquippableItemSystem for EquippableItemPrefabAsset } else { string _path = SaveSystem.GetSavePath(this.MapName + DYNAMIC_ELEMENT) + "/" + this.ItemsListName + ".fun"; @@ -276,9 +276,9 @@ public class SceneEquippableItemManager : MonoBehaviour { Debug.Log(file.FullName); - EquippableItemPrefarbAssetData equippableItemPrefarbAssetData = SaveEquippableItemSystem.LoadEquitableItem(file.Name, this.MapName + DYNAMIC_ELEMENT + this.ElementFolderName); + EquippableItemPrefabAssetData equippableItemPrefarbAssetData = SaveEquippableItemSystem.LoadEquitableItem(file.Name, this.MapName + DYNAMIC_ELEMENT + this.ElementFolderName); - DynamicElements.Add(equippableItemPrefarbAssetData.MapDataToEquippableItemPrefarbAsset()); + DynamicElements.Add((EquippableItemPrefabAsset)((EquippableItemPrefabAssetData)equippableItemPrefarbAssetData).MapDataToPrefabAssetModel()); } } @@ -296,10 +296,10 @@ public class SceneEquippableItemManager : MonoBehaviour if(file.Name != this.ItemsListName + ".fun") continue; - List equippableItemPrefarbAssetDataList = SaveEquippableItemSystem.LoadEquitableItemList(this.MapName + DYNAMIC_ELEMENT, this.ItemsListName); + List equippableItemPrefarbAssetDataList = SaveEquippableItemSystem.LoadEquitableItemList(this.MapName + DYNAMIC_ELEMENT, this.ItemsListName); - foreach(EquippableItemPrefarbAssetData equippableItemPrefarbAssetData in equippableItemPrefarbAssetDataList) - DynamicElements.Add(equippableItemPrefarbAssetData.MapDataToEquippableItemPrefarbAsset()); + foreach(EquippableItemPrefabAssetData equippableItemPrefarbAssetData in equippableItemPrefarbAssetDataList) + DynamicElements.Add((EquippableItemPrefabAsset)((EquippableItemPrefabAssetData)equippableItemPrefarbAssetData).MapDataToPrefabAssetModel()); } } #endregion @@ -318,9 +318,9 @@ public class SceneEquippableItemManager : MonoBehaviour { Debug.Log(file.FullName); - EquippableItemPrefarbAssetData equippableItemPrefarbAssetData = SaveEquippableItemSystem.LoadEquitableItem(file.Name, this.MapName + STATIC_ELEMENT + this.ElementFolderName); + EquippableItemPrefabAssetData equippableItemPrefarbAssetData = SaveEquippableItemSystem.LoadEquitableItem(file.Name, this.MapName + STATIC_ELEMENT + this.ElementFolderName); - StaticElements.Add(equippableItemPrefarbAssetData.MapDataToEquippableItemPrefarbAsset()); + StaticElements.Add((EquippableItemPrefabAsset)((EquippableItemPrefabAssetData)equippableItemPrefarbAssetData).MapDataToPrefabAssetModel()); } } @@ -337,10 +337,10 @@ public class SceneEquippableItemManager : MonoBehaviour { Debug.Log(file.FullName); - List equippableItemPrefarbAssetDataList = SaveEquippableItemSystem.LoadEquitableItemList(this.MapName + STATIC_ELEMENT, this.ItemsListName); + List equippableItemPrefarbAssetDataList = SaveEquippableItemSystem.LoadEquitableItemList(this.MapName + STATIC_ELEMENT, this.ItemsListName); - foreach(EquippableItemPrefarbAssetData equippableItemPrefarbAssetData in equippableItemPrefarbAssetDataList) - StaticElements.Add(equippableItemPrefarbAssetData.MapDataToEquippableItemPrefarbAsset()); + foreach(EquippableItemPrefabAssetData equippableItemPrefarbAssetData in equippableItemPrefarbAssetDataList) + StaticElements.Add((EquippableItemPrefabAsset)((EquippableItemPrefabAssetData)equippableItemPrefarbAssetData).MapDataToPrefabAssetModel()); } } #endregion