diff --git a/Assets/Prefabs/InventoryItem.prefab b/Assets/Prefabs/InventoryItem.prefab new file mode 100644 index 0000000..a907849 --- /dev/null +++ b/Assets/Prefabs/InventoryItem.prefab @@ -0,0 +1,244 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &6195981407214780322 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6195981407214780323} + - component: {fileID: 6195981407214780321} + - component: {fileID: 6195981407214780320} + m_Layer: 5 + m_Name: Count + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &6195981407214780323 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6195981407214780322} + 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: [] + m_Father: {fileID: 6195981408798853131} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 14.4, y: -11.8} + m_SizeDelta: {x: 24, y: 16} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &6195981407214780321 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6195981407214780322} + m_CullTransparentMesh: 1 +--- !u!114 &6195981407214780320 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6195981407214780322} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: 0 + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294967295 + m_fontColor: {r: 1, g: 1, b: 1, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 16 + m_fontSizeBase: 16 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 0 + m_HorizontalAlignment: 1 + m_VerticalAlignment: 256 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!1 &6195981408798853130 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6195981408798853131} + - component: {fileID: 6195981408798853126} + - component: {fileID: 6195981408798853129} + - component: {fileID: 6195981408798853128} + - component: {fileID: 6195981408798853127} + m_Layer: 5 + m_Name: InventoryItem + m_TagString: InventoryItem + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &6195981408798853131 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6195981408798853130} + 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: 6195981407214780323} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 40, y: 40} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &6195981408798853126 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6195981408798853130} + m_CullTransparentMesh: 1 +--- !u!114 &6195981408798853129 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6195981408798853130} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 0} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!114 &6195981408798853128 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6195981408798853130} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: df6ce7a69909db74abdeea33fadaf46a, type: 3} + m_Name: + m_EditorClassIdentifier: + ItemStack: + ItemId: -1 + Size: 0 + ItemSlot: {fileID: 0} + count: {fileID: 6195981407214780320} + onDragAlpha: 1 +--- !u!225 &6195981408798853127 +CanvasGroup: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6195981408798853130} + m_Enabled: 1 + m_Alpha: 1 + m_Interactable: 1 + m_BlocksRaycasts: 1 + m_IgnoreParentGroups: 0 diff --git a/Assets/Prefabs/InventoryItem.prefab.meta b/Assets/Prefabs/InventoryItem.prefab.meta new file mode 100644 index 0000000..e2ab3b0 --- /dev/null +++ b/Assets/Prefabs/InventoryItem.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f351304e594bc2342a44489b84acbf9d +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/PlayerInventorySlot.prefab b/Assets/Prefabs/PlayerInventorySlot.prefab index d64a38b..98898f9 100644 --- a/Assets/Prefabs/PlayerInventorySlot.prefab +++ b/Assets/Prefabs/PlayerInventorySlot.prefab @@ -9,6 +9,9 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 8828641747527187352} + - component: {fileID: 4891780958647980299} + - component: {fileID: 7163577800468536673} + - component: {fileID: 2396239915488732509} m_Layer: 5 m_Name: PlayerInventorySlot m_TagString: Untagged @@ -26,9 +29,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_Children: - - {fileID: 8828641747749458312} - - {fileID: 8828641748315223567} + m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -37,58 +38,33 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 40, y: 40} m_Pivot: {x: 0.5, y: 0.5} ---- !u!1 &8828641747749458313 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 8828641747749458312} - - component: {fileID: 8828641747749458314} - - component: {fileID: 8828641747749458315} - m_Layer: 5 - m_Name: Sprite - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &8828641747749458312 -RectTransform: +--- !u!114 &4891780958647980299 +MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8828641747749458313} - 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: [] - m_Father: {fileID: 8828641747527187352} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 40, y: 40} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!222 &8828641747749458314 + m_GameObject: {fileID: 8828641747527187353} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 39fb2f650cad7b44daec14cde6791573, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!222 &7163577800468536673 CanvasRenderer: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8828641747749458313} + m_GameObject: {fileID: 8828641747527187353} m_CullTransparentMesh: 1 ---- !u!114 &8828641747749458315 +--- !u!114 &2396239915488732509 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8828641747749458313} + m_GameObject: {fileID: 8828641747527187353} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} @@ -112,137 +88,3 @@ MonoBehaviour: m_FillOrigin: 0 m_UseSpriteMesh: 0 m_PixelsPerUnitMultiplier: 1 ---- !u!1 &8828641748315223564 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 8828641748315223567} - - component: {fileID: 8828641748315223553} - - component: {fileID: 8828641748315223566} - m_Layer: 5 - m_Name: Count - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &8828641748315223567 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8828641748315223564} - 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: [] - m_Father: {fileID: 8828641747527187352} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 1.3, y: -13.8} - m_SizeDelta: {x: 28, y: 28} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!222 &8828641748315223553 -CanvasRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8828641748315223564} - m_CullTransparentMesh: 1 ---- !u!114 &8828641748315223566 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8828641748315223564} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 - m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} - m_Maskable: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_text: - m_isRightToLeft: 0 - m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} - m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} - m_fontSharedMaterials: [] - m_fontMaterial: {fileID: 0} - m_fontMaterials: [] - m_fontColor32: - serializedVersion: 2 - rgba: 4294967295 - m_fontColor: {r: 1, g: 1, b: 1, a: 1} - m_enableVertexGradient: 0 - m_colorMode: 3 - m_fontColorGradient: - topLeft: {r: 1, g: 1, b: 1, a: 1} - topRight: {r: 1, g: 1, b: 1, a: 1} - bottomLeft: {r: 1, g: 1, b: 1, a: 1} - bottomRight: {r: 1, g: 1, b: 1, a: 1} - m_fontColorGradientPreset: {fileID: 0} - m_spriteAsset: {fileID: 0} - m_tintAllSprites: 0 - m_StyleSheet: {fileID: 0} - m_TextStyleHashCode: -1183493901 - m_overrideHtmlColors: 0 - m_faceColor: - serializedVersion: 2 - rgba: 4294967295 - m_fontSize: 16 - m_fontSizeBase: 16 - m_fontWeight: 400 - m_enableAutoSizing: 0 - m_fontSizeMin: 18 - m_fontSizeMax: 72 - m_fontStyle: 0 - m_HorizontalAlignment: 2 - m_VerticalAlignment: 256 - m_textAlignment: 65535 - m_characterSpacing: 0 - m_wordSpacing: 0 - m_lineSpacing: 0 - m_lineSpacingMax: 0 - m_paragraphSpacing: 0 - m_charWidthMaxAdj: 0 - m_enableWordWrapping: 1 - m_wordWrappingRatios: 0.4 - m_overflowMode: 0 - m_linkedTextComponent: {fileID: 0} - parentLinkedComponent: {fileID: 0} - m_enableKerning: 1 - m_enableExtraPadding: 0 - checkPaddingRequired: 0 - m_isRichText: 1 - m_parseCtrlCharacters: 1 - m_isOrthographic: 1 - m_isCullingEnabled: 0 - m_horizontalMapping: 0 - m_verticalMapping: 0 - m_uvLineOffset: 0 - m_geometrySortingOrder: 0 - m_IsTextObjectScaleStatic: 0 - m_VertexBufferAutoSizeReduction: 0 - m_useMaxVisibleDescender: 1 - m_pageToDisplay: 1 - m_margin: {x: 8.43634, y: 0, z: -3.9102783, w: 9.169952} - m_isUsingLegacyAnimationComponent: 0 - m_isVolumetricText: 0 - m_hasFontAssetChanged: 0 - m_baseMaterial: {fileID: 0} - m_maskOffset: {x: 0, y: 0, z: 0, w: 0} diff --git a/Assets/Prefabs/PlayerInventoryUI.prefab b/Assets/Prefabs/PlayerInventoryUI.prefab index 8b6e73d..131d13e 100644 --- a/Assets/Prefabs/PlayerInventoryUI.prefab +++ b/Assets/Prefabs/PlayerInventoryUI.prefab @@ -188,6 +188,8 @@ MonoBehaviour: pointerOffset: {x: 0, y: -40, z: 0} slotPrefab: {fileID: 8828641747527187353, guid: a644058a9d717294a88def6afbe2eb3b, type: 3} + inventoryItemPrefab: {fileID: 6195981408798853130, guid: f351304e594bc2342a44489b84acbf9d, + type: 3} contentTransform: {fileID: 6897256475441182503} emptySlotSprite: {fileID: 21300000, guid: 8196e66c2d14208458afa4802e37ba0b, type: 3} slotPointer: {fileID: 127808939} diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 66b4b8c..98bcae9 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -203,7 +203,7 @@ GameObject: - component: {fileID: 422223276} m_Layer: 5 m_Name: Canvas - m_TagString: Untagged + m_TagString: Canvas m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -290,6 +290,12 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 0} +--- !u!224 &1041888784 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 45638323530593135, guid: 66c87ca477b2e1c469075df8de33eab4, + type: 3} + m_PrefabInstance: {fileID: 3786220006244098176} + m_PrefabAsset: {fileID: 0} --- !u!1 &1046488790 GameObject: m_ObjectHideFlags: 0 @@ -853,6 +859,11 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 4583365050578613208, guid: 66c87ca477b2e1c469075df8de33eab4, + type: 3} + propertyPath: m_Viewport + value: + objectReference: {fileID: 1041888784} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 66c87ca477b2e1c469075df8de33eab4, type: 3} --- !u!1001 &8447453228056732653 diff --git a/Assets/Scripts/Events/EiramEvents.cs b/Assets/Scripts/Events/EiramEvents.cs index 07c6925..c3b7541 100644 --- a/Assets/Scripts/Events/EiramEvents.cs +++ b/Assets/Scripts/Events/EiramEvents.cs @@ -29,18 +29,12 @@ public static void OnPlayerToggleInventory(PlayerInventory playerInventory) PlayerToggleInventoryEvent?.Invoke(playerInventory); } - public static event Action PlayerInventoryIsDirtyEvent; + public static event Action SelectedSlotChangedEvent; - public static void OnPlayerInventoryIsDirty(PlayerInventory playerInventory) + public static void SelectedSlotChanged(int slotIndex) { - PlayerInventoryIsDirtyEvent?.Invoke(playerInventory); + SelectedSlotChangedEvent?.Invoke(slotIndex); } - public static event Action SelectedSlotChangedEvent; - - public static void SelectedSlotChanged(PlayerInventory playerInventory, int slotIndex) - { - SelectedSlotChangedEvent?.Invoke(playerInventory, slotIndex); - } } } \ No newline at end of file diff --git a/Assets/Scripts/Inventories/Inventory.cs b/Assets/Scripts/Inventories/Inventory.cs index d904a7c..2a5a6a7 100644 --- a/Assets/Scripts/Inventories/Inventory.cs +++ b/Assets/Scripts/Inventories/Inventory.cs @@ -82,9 +82,13 @@ public ItemStack RemoveFromItemStack(int slotIndex, int amount = 1) } stack.Size -= amount; + + var toReturn = new ItemStack(stack.ItemId, amount); + if(stack.Size == 0) ItemStacks[slotIndex].Empty(); - return new ItemStack(stack.ItemId, amount); + + return toReturn; } return new ItemStack(); @@ -124,5 +128,11 @@ public int NextEmptySlot() return -1; } + + public void ClearSlot(int slotNumber) + { + ItemStacks[slotNumber] = new ItemStack(); + IsDirty = true; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Inventories/InventoryItem.cs b/Assets/Scripts/Inventories/InventoryItem.cs new file mode 100644 index 0000000..9e13ae5 --- /dev/null +++ b/Assets/Scripts/Inventories/InventoryItem.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using Events; +using Items; +using Registers; +using TMPro; +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.Serialization; +using UnityEngine.UI; + +public class InventoryItem : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler +{ + public ItemStack ItemStack; + public ItemSlot ItemSlot; + + [SerializeField] private TMP_Text count = null; + [SerializeField] private float onDragAlpha = 1.0f; + + private ItemSlot lastItemSlot; + private RectTransform rectTransform = null; + private Canvas canvas = null; + private CanvasGroup canvasGroup = null; + private Image image = null; + + private void Awake() + { + rectTransform = GetComponent(); + canvasGroup = GetComponent(); + canvas = GameObject.FindGameObjectWithTag("Canvas").GetComponent(); + image = GetComponent(); + } + + public void Refresh() + { + count.text = ItemStack.Size.ToString(); + image.sprite = Register.GetItemById(ItemStack.ItemId).sprite; + } + + public void OnPointerDown(PointerEventData eventData) + { + transform.SetParent(canvas.transform); + } + + public void OnDrag(PointerEventData eventData) + { + rectTransform.anchoredPosition += (eventData.delta / canvas.scaleFactor); + } + + public void OnBeginDrag(PointerEventData eventData) + { + canvasGroup.blocksRaycasts = false; + canvasGroup.alpha = onDragAlpha; + + Debug.Log("drag start"); + ItemSlot.ItemPopped(); + lastItemSlot = ItemSlot; + ItemSlot = null; + } + + public void OnEndDrag(PointerEventData eventData) + { + if (ItemSlot == null) + { + ItemSlot = lastItemSlot; + ItemSlot.ItemPlaced(this); + } + else + { + lastItemSlot = null; + } + canvasGroup.blocksRaycasts = true; + canvasGroup.alpha = 1.0f; + Debug.Log("drag end"); + + } +} diff --git a/Assets/Scripts/Inventories/InventoryItem.cs.meta b/Assets/Scripts/Inventories/InventoryItem.cs.meta new file mode 100644 index 0000000..babbf01 --- /dev/null +++ b/Assets/Scripts/Inventories/InventoryItem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: df6ce7a69909db74abdeea33fadaf46a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Inventories/InventoryUI.cs b/Assets/Scripts/Inventories/InventoryUI.cs new file mode 100644 index 0000000..d48da00 --- /dev/null +++ b/Assets/Scripts/Inventories/InventoryUI.cs @@ -0,0 +1,10 @@ +using Items; + +namespace Inventories +{ + public interface InventoryUI + { + void ItemPopped(int itemSlot); + void ItemPlaced(int itemSlot, ItemStack itemStack); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Inventories/InventoryUI.cs.meta b/Assets/Scripts/Inventories/InventoryUI.cs.meta new file mode 100644 index 0000000..88f2b23 --- /dev/null +++ b/Assets/Scripts/Inventories/InventoryUI.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 505a615ec9cc4035ba9dc5f9a78f67d2 +timeCreated: 1636740645 \ No newline at end of file diff --git a/Assets/Scripts/Inventories/ItemSlot.cs b/Assets/Scripts/Inventories/ItemSlot.cs new file mode 100644 index 0000000..da511ff --- /dev/null +++ b/Assets/Scripts/Inventories/ItemSlot.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using Eiram; +using Events; +using Inventories; +using Items; +using TMPro; +using UnityEngine; +using UnityEngine.EventSystems; + +public class ItemSlot : MonoBehaviour, IDropHandler +{ + public InventoryItem inventoryItem; + public int slotNumber = -1; + public InventoryUI InventoryUI; + + private RectTransform rectTransform; + + private void Awake() + { + rectTransform = GetComponent(); + } + + public void Refresh() + { + if(inventoryItem != null) + inventoryItem.Refresh(); + } + + public void ItemPopped() + { + inventoryItem = null; + InventoryUI.ItemPopped(slotNumber); + } + + public void ItemPlaced(InventoryItem inventoryItem) + { + this.inventoryItem = inventoryItem; + InventoryUI.ItemPlaced(slotNumber, inventoryItem.ItemStack); + AlignInventoryItem(); + } + + public void Clear() + { + if (inventoryItem != null) + { + Destroy(inventoryItem.gameObject); + inventoryItem = null; + } + } + + public bool IsEmpty() + { + return inventoryItem == null; + } + + public void OnDrop(PointerEventData eventData) + { + if (eventData == null || eventData.pointerDrag == null) return; + + if (!eventData.pointerDrag.CompareTag("InventoryItem")) return; + + + inventoryItem = eventData.pointerDrag.GetComponent(); + inventoryItem.ItemSlot = this; + InventoryUI.ItemPlaced(slotNumber, inventoryItem.ItemStack); + AlignInventoryItem(); + } + + public void AlignInventoryItem() + { + var otherTransform = inventoryItem.GetComponent(); + otherTransform.SetParent(rectTransform); + otherTransform.anchoredPosition = new Vector3(0.0f, 0.0f, 0.0f); + } + +} diff --git a/Assets/Scripts/Inventories/ItemSlot.cs.meta b/Assets/Scripts/Inventories/ItemSlot.cs.meta new file mode 100644 index 0000000..6ed137b --- /dev/null +++ b/Assets/Scripts/Inventories/ItemSlot.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 39fb2f650cad7b44daec14cde6791573 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Inventories/PlayerInventory.cs b/Assets/Scripts/Inventories/PlayerInventory.cs index 3ea3d42..f2c280e 100644 --- a/Assets/Scripts/Inventories/PlayerInventory.cs +++ b/Assets/Scripts/Inventories/PlayerInventory.cs @@ -24,14 +24,14 @@ public void SelectNext() { selectedSlot++; if (selectedSlot >= hotbarSlotsCount) selectedSlot = 0; - EiramEvents.SelectedSlotChanged(this, selectedSlot); + EiramEvents.SelectedSlotChanged(selectedSlot); } public void SelectPrevious() { selectedSlot--; if (selectedSlot < 0) selectedSlot = hotbarSlotsCount - 1; - EiramEvents.SelectedSlotChanged(this, selectedSlot); + EiramEvents.SelectedSlotChanged(selectedSlot); } public ItemStack PopSelectedItem() diff --git a/Assets/Scripts/Inventories/PlayerInventoryUI.cs b/Assets/Scripts/Inventories/PlayerInventoryUI.cs index f38b6fb..aba4bf9 100644 --- a/Assets/Scripts/Inventories/PlayerInventoryUI.cs +++ b/Assets/Scripts/Inventories/PlayerInventoryUI.cs @@ -1,103 +1,130 @@ using System; using System.Collections.Generic; -using Eiram; using Events; using Items; +using Players; using Registers; -using TMPro; using UnityEngine; -using UnityEngine.Serialization; using UnityEngine.UI; namespace Inventories { - public class PlayerInventoryUI : MonoBehaviour + public class PlayerInventoryUI : MonoBehaviour, InventoryUI { [SerializeField] private Vector3 pointerOffset = new Vector3(); - [SerializeField] private GameObject slotPrefab; - [SerializeField] private RectTransform contentTransform; - [SerializeField] private Sprite emptySlotSprite = null; + [SerializeField] private GameObject slotPrefab = null; + [SerializeField] private GameObject inventoryItemPrefab = null; + [SerializeField] private RectTransform contentTransform = null; [SerializeField] private GameObject slotPointer = null; - - private List itemSprites = new List(PlayerInventory.Slots); - private List itemCounts = new List(PlayerInventory.Slots); - + + private Canvas canvas; + private List itemSlots = new List(PlayerInventory.Slots); + private PlayerInventory playerInventory; private bool toggled = false; private void Awake() { EiramEvents.PlayerToggleInventoryEvent += OnPlayerToggleInventoryEvent; - EiramEvents.PlayerInventoryIsDirtyEvent += OnPlayerInventoryIsDirty; EiramEvents.SelectedSlotChangedEvent += OnSelectedSlotChanged; + + canvas = GameObject.FindGameObjectWithTag("Canvas").GetComponent(); + GenerateUI(); } + private void Start() + { + playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent().playerInventory; + } + + private void Update() + { + if (playerInventory.IsDirty) + { + playerInventory.IsDirty = false; + Refresh(); + } + } + private void OnDestroy() { EiramEvents.PlayerToggleInventoryEvent -= OnPlayerToggleInventoryEvent; - EiramEvents.PlayerInventoryIsDirtyEvent -= OnPlayerInventoryIsDirty; EiramEvents.SelectedSlotChangedEvent -= OnSelectedSlotChanged; } + public void ItemPopped(int slotNumber) + { + playerInventory.ClearSlot(slotNumber); + } + + public void ItemPlaced(int itemSlot, ItemStack itemStack) + { + playerInventory.ItemStacks[itemSlot] = itemStack; + playerInventory.IsDirty = true; + } + private void GenerateUI() { for (int i = 0; i < PlayerInventory.Slots; i++) { var go = Instantiate(slotPrefab, contentTransform); - itemSprites.Add(go.GetComponentInChildren()); - itemCounts.Add(go.GetComponentInChildren()); + var itemSlot = go.GetComponent(); + itemSlot.slotNumber = i; + itemSlot.InventoryUI = this; + itemSlots.Add(itemSlot); } } private void MovePointer(int slotIndex) { - var pos = itemSprites[slotIndex].gameObject.transform.position; + var pos = itemSlots[slotIndex].gameObject.transform.position; slotPointer.transform.position = pos + pointerOffset; } private void OnPlayerToggleInventoryEvent(PlayerInventory playerInventory) { - Debug.Assert(PlayerInventory.Slots == itemSprites.Count && PlayerInventory.Slots == itemCounts.Count); - if(toggled) CloseInventory(); else OpenInventory(playerInventory); + Debug.Assert(PlayerInventory.Slots == itemSlots.Count); + if(toggled) CloseInventory(); else OpenInventory(); toggled = !toggled; + Refresh(); } - private void OnPlayerInventoryIsDirty(PlayerInventory playerInventory) - { - Refresh(playerInventory); - } - - private void OnSelectedSlotChanged(PlayerInventory playerInventory, int slotIndex) + private void OnSelectedSlotChanged(int slotIndex) { MovePointer(slotIndex); } - private void Refresh(PlayerInventory playerInventory) + private void Refresh() { - for (int i = 0; i < playerInventory.ItemStacks.Count; i++) + for(int i = 0; i < playerInventory.ItemStacks.Count; i++) { - var currentItemStack = playerInventory.ItemStacks[i]; - if (!currentItemStack.IsEmpty()) + var itemStack = playerInventory.ItemStacks[i]; + var itemSlot = itemSlots[i]; + if (!itemStack.IsEmpty() && itemSlot.IsEmpty()) { - var item = Register.GetItemById(currentItemStack.ItemId); - itemSprites[i].sprite = item.sprite; - itemCounts[i].gameObject.SetActive(true); - itemCounts[i].text = currentItemStack.Size.ToString(); + var inventoryItemGo = Instantiate(inventoryItemPrefab, itemSlots[i].transform); + var inventoryItem = inventoryItemGo.GetComponent(); + + inventoryItem.ItemStack = itemStack; + inventoryItem.ItemSlot = itemSlot; + + itemSlot.inventoryItem = inventoryItem; } - else + + if (itemStack.IsEmpty()) { - itemSprites[i].sprite = emptySlotSprite; - itemCounts[i].text = "0"; - itemCounts[i].gameObject.SetActive(false); + itemSlot.Clear(); } + + itemSlot.Refresh(); } } - private void OpenInventory(PlayerInventory playerInventory) + private void OpenInventory() { LeanTween.moveY(gameObject, transform.position.y - 460.0f, 0.4f); - Refresh(playerInventory); + Refresh(); } private void CloseInventory() diff --git a/Assets/Scripts/Players/Player.cs b/Assets/Scripts/Players/Player.cs index 9b49127..d896f03 100644 --- a/Assets/Scripts/Players/Player.cs +++ b/Assets/Scripts/Players/Player.cs @@ -13,12 +13,13 @@ namespace Players //[RequireComponent(typeof(Animator))] public class Player : MonoBehaviour { + public PlayerInventory playerInventory; + [SerializeField] private float jumpForce = 400f; [SerializeField] private float movementSpeed = 10f; private Camera mainCamera = null; private CharacterController controller = null; - private PlayerInventory playerInventory = new PlayerInventory(); // private Animator animator = null; private bool isPlayerIdle = true; @@ -40,13 +41,6 @@ void Update() CheckForMouseInput(); CheckPlayerJump(); CheckPlayerIdle(); - - // TODO: the player should not need to handle this - if (playerInventory.IsDirty) - { - EiramEvents.OnPlayerInventoryIsDirty(playerInventory); - playerInventory.IsDirty = false; - } } public void ApplyPlayerData(PlayerData playerData) diff --git a/Assets/Scripts/Worlds/World.cs b/Assets/Scripts/Worlds/World.cs index 91072df..f5e3ca4 100644 --- a/Assets/Scripts/Worlds/World.cs +++ b/Assets/Scripts/Worlds/World.cs @@ -32,12 +32,12 @@ private void Awake() playerObject = GameObject.FindGameObjectWithTag("Player"); player = playerObject.GetComponent(); Save = Filesystem.CreateSave("DEBUG_SAVE"); + LoadWorld(); } void Start() { InvokeRepeating(nameof(ChunkRefresh), 0.0f, 1.0f); - LoadWorld(); } private void OnDestroy() diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 97a9e34..616a22d 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -7,6 +7,7 @@ TagManager: - TerrainTilemap - World - ItemEntity + - Canvas layers: - Default - TransparentFX