From 07e88a88fea29d017aa15c46548a0313c2114fd5 Mon Sep 17 00:00:00 2001 From: Michal Pikulski Date: Tue, 9 Sep 2025 13:38:03 +0200 Subject: [PATCH] OneClickInteractable --- Assets/Scenes/Levels/Quarry.unity | 17 ++++++++- Assets/Scripts/Interactions/Interactable.cs | 5 +++ .../Interactions/OneClickInteraction.cs | 35 +++++++++++++++++++ .../Interactions/OneClickInteraction.cs.meta | 3 ++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 Assets/Scripts/Interactions/OneClickInteraction.cs create mode 100644 Assets/Scripts/Interactions/OneClickInteraction.cs.meta diff --git a/Assets/Scenes/Levels/Quarry.unity b/Assets/Scenes/Levels/Quarry.unity index c630bfbe..cedd1123 100644 --- a/Assets/Scenes/Levels/Quarry.unity +++ b/Assets/Scenes/Levels/Quarry.unity @@ -433017,7 +433017,7 @@ PrefabInstance: objectReference: {fileID: 11400000, guid: 5861b0a3b22b57f43a00cab7c7faafaa, type: 2} - target: {fileID: 1498439134679474750, guid: 93ab59741ddc4e045a61cd8e05b65578, type: 3} propertyPath: m_Name - value: Diving for Pictures + value: DivingForPictures objectReference: {fileID: 0} - target: {fileID: 4428217320659622763, guid: 93ab59741ddc4e045a61cd8e05b65578, type: 3} propertyPath: m_LocalScale.x @@ -434378,6 +434378,18 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: stepData: {fileID: 11400000, guid: 8ac614a698631554ab8ac39aed04a189, type: 2} +--- !u!114 &1182494941 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1182494929} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 833a4ccef651449e973e623d9107bef5, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &1192177492 PrefabInstance: m_ObjectHideFlags: 0 @@ -441399,6 +441411,9 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 7379304988657006554, guid: c36b48a324dcaef4cb5ee0f8ca57f0d6, type: 3} insertIndex: -1 addedObject: {fileID: 1182494937} + - targetCorrespondingSourceObject: {fileID: 7379304988657006554, guid: c36b48a324dcaef4cb5ee0f8ca57f0d6, type: 3} + insertIndex: -1 + addedObject: {fileID: 1182494941} m_SourcePrefab: {fileID: 100100000, guid: c36b48a324dcaef4cb5ee0f8ca57f0d6, type: 3} --- !u!1001 &7535757761066548300 PrefabInstance: diff --git a/Assets/Scripts/Interactions/Interactable.cs b/Assets/Scripts/Interactions/Interactable.cs index 5966e58d..bab8a866 100644 --- a/Assets/Scripts/Interactions/Interactable.cs +++ b/Assets/Scripts/Interactions/Interactable.cs @@ -68,4 +68,9 @@ public class Interactable : MonoBehaviour, ITouchInputConsumer } return anySuccess; } + + public void CompleteInteraction(bool success) + { + InteractionComplete?.Invoke(success); + } } diff --git a/Assets/Scripts/Interactions/OneClickInteraction.cs b/Assets/Scripts/Interactions/OneClickInteraction.cs new file mode 100644 index 00000000..c53fa477 --- /dev/null +++ b/Assets/Scripts/Interactions/OneClickInteraction.cs @@ -0,0 +1,35 @@ +using UnityEngine; +using System; + +/// +/// MonoBehaviour that immediately completes an interaction when started. +/// +public class OneClickInteraction : MonoBehaviour +{ + private Interactable interactable; + + void Awake() + { + interactable = GetComponent(); + if (interactable != null) + { + interactable.StartedInteraction += OnStartedInteraction; + } + } + + void OnDestroy() + { + if (interactable != null) + { + interactable.StartedInteraction -= OnStartedInteraction; + } + } + + private void OnStartedInteraction() + { + if (interactable != null) + { + interactable.CompleteInteraction(true); + } + } +} diff --git a/Assets/Scripts/Interactions/OneClickInteraction.cs.meta b/Assets/Scripts/Interactions/OneClickInteraction.cs.meta new file mode 100644 index 00000000..f19903d4 --- /dev/null +++ b/Assets/Scripts/Interactions/OneClickInteraction.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 833a4ccef651449e973e623d9107bef5 +timeCreated: 1757417586 \ No newline at end of file