From 9df43b8f53e74a28e2509c6171031cf12e22d379 Mon Sep 17 00:00:00 2001 From: Damian Date: Mon, 20 Oct 2025 16:19:08 +0200 Subject: [PATCH] Implemented Flash Feedback to the Diving Minigame --- .../Scenes/MiniGames/DivingForPictures.unity | 182 ++++++++++++++++-- .../Minigame/FlashBehaviour.cs | 69 +++++++ .../Minigame/FlashBehaviour.cs.meta | 2 + .../DivingForPictures/DivingGameManager.cs | 21 +- 4 files changed, 251 insertions(+), 23 deletions(-) create mode 100644 Assets/Scripts/DamianExperiments/Minigame/FlashBehaviour.cs create mode 100644 Assets/Scripts/DamianExperiments/Minigame/FlashBehaviour.cs.meta diff --git a/Assets/Scenes/MiniGames/DivingForPictures.unity b/Assets/Scenes/MiniGames/DivingForPictures.unity index 094f425c..89873e5c 100644 --- a/Assets/Scenes/MiniGames/DivingForPictures.unity +++ b/Assets/Scenes/MiniGames/DivingForPictures.unity @@ -343,15 +343,15 @@ LineRenderer: m_SortingOrder: 0 m_Positions: - {x: -0.15602553, y: 4.0749445, z: 0} - - {x: -0.1566351, y: 3.9736373, z: 0} - - {x: -0.1572447, y: 3.8729854, z: 0} - - {x: -0.15785426, y: 3.772987, z: 0} - - {x: -0.15846384, y: 3.6736436, z: 0} - - {x: -0.15907341, y: 3.5749538, z: 0} - - {x: -0.15968299, y: 3.476919, z: 0} - - {x: -0.16029257, y: 3.3795383, z: 0} - - {x: -0.16090216, y: 3.282812, z: 0} - - {x: -0.16151173, y: 3.1867404, z: 0} + - {x: -0.1566351, y: 3.9736378, z: 0} + - {x: -0.1572447, y: 3.8729858, z: 0} + - {x: -0.15785426, y: 3.7729874, z: 0} + - {x: -0.15846384, y: 3.6736438, z: 0} + - {x: -0.15907341, y: 3.5749543, z: 0} + - {x: -0.15968299, y: 3.4769194, z: 0} + - {x: -0.16029257, y: 3.3795385, z: 0} + - {x: -0.16090216, y: 3.2828126, z: 0} + - {x: -0.16151173, y: 3.1867406, z: 0} - {x: -0.16212131, y: 3.0913231, z: 0} m_Parameters: serializedVersion: 3 @@ -778,6 +778,7 @@ MonoBehaviour: - {fileID: 1062017697} - {fileID: 173052728} surfacingTimeline: {fileID: 2064311130} + flashRef: {fileID: 1419181041} deathAudioPlayer: {fileID: 199536377} --- !u!4 &424805726 Transform: @@ -1046,7 +1047,7 @@ Transform: m_GameObject: {fileID: 747976396} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 3.197517, z: 0} + m_LocalPosition: {x: 0, y: 3.1975174, z: 0} m_LocalScale: {x: 0.57574, y: 0.57574, z: 0.57574} m_ConstrainProportionsScale: 0 m_Children: @@ -1597,12 +1598,12 @@ LineRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_Positions: - - {x: -0.15602553, y: 4.0749445, z: 0} - - {x: -0.11662118, y: 3.879622, z: 0} + - {x: -0.15602553, y: 4.074945, z: 0} + - {x: -0.11662118, y: 3.8796225, z: 0} - {x: -0.07721684, y: 3.7057445, z: 0} - - {x: -0.03781248, y: 3.5533104, z: 0} - - {x: 0.0015918687, y: 3.4223213, z: 0} - - {x: 0.040996216, y: 3.312776, z: 0} + - {x: -0.03781248, y: 3.5533106, z: 0} + - {x: 0.0015918687, y: 3.4223216, z: 0} + - {x: 0.040996216, y: 3.3127766, z: 0} - {x: 0.08040057, y: 3.2246757, z: 0} - {x: 0.11980491, y: 3.1580195, z: 0} - {x: 0.15920927, y: 3.1128078, z: 0} @@ -2293,6 +2294,54 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 +--- !u!1 &1419181041 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1419181043} + - component: {fileID: 1419181042} + m_Layer: 0 + m_Name: Flash + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1419181042 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1419181041} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 194155c0137366c4ea64558d2601e19a, type: 3} + m_Name: + m_EditorClassIdentifier: AppleHillsScripts::FlashBehaviour + square: {fileID: 2005292373} + flashInDuration: 0.05 + flashOutDuration: 0.2 +--- !u!4 &1419181043 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1419181041} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: -10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 2005292375} + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1435210807 GameObject: m_ObjectHideFlags: 0 @@ -2398,14 +2447,14 @@ LineRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_Positions: - - {x: -0.15602553, y: 4.0749445, z: 0} - - {x: -0.18956745, y: 3.8764973, z: 0} + - {x: -0.15602553, y: 4.074945, z: 0} + - {x: -0.18956745, y: 3.8764977, z: 0} - {x: -0.22310936, y: 3.7000232, z: 0} - - {x: -0.25665125, y: 3.54552, z: 0} - - {x: -0.29019317, y: 3.4129906, z: 0} - - {x: -0.32373506, y: 3.302433, z: 0} + - {x: -0.25665125, y: 3.5455205, z: 0} + - {x: -0.29019317, y: 3.4129908, z: 0} + - {x: -0.32373506, y: 3.3024333, z: 0} - {x: -0.35727698, y: 3.213848, z: 0} - - {x: -0.39081886, y: 3.1472354, z: 0} + - {x: -0.39081886, y: 3.1472356, z: 0} - {x: -0.4243608, y: 3.1025953, z: 0} - {x: -0.45790267, y: 3.0799277, z: 0} - {x: -0.4914446, y: 3.0792325, z: 0} @@ -2971,6 +3020,96 @@ Transform: m_Children: [] m_Father: {fileID: 747976397} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &2005292373 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2005292375} + - component: {fileID: 2005292374} + m_Layer: 0 + m_Name: Square + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!212 &2005292374 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2005292373} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RayTracingAccelStructBuildFlagsOverride: 0 + m_RayTracingAccelStructBuildFlags: 1 + m_SmallMeshCulling: 1 + m_ForceMeshLod: -1 + m_MeshLodSelectionBias: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_GlobalIlluminationMeshLod: 0 + m_SortingLayerID: -1132846201 + m_SortingLayer: 1 + m_SortingOrder: 10 + m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 0} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 1, y: 1} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!4 &2005292375 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2005292373} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 10} + m_LocalScale: {x: 17.9979, y: 19.838, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1419181043} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2010418241 GameObject: m_ObjectHideFlags: 0 @@ -3226,6 +3365,7 @@ SceneRoots: - {fileID: 1063641114} - {fileID: 224729333} - {fileID: 747976397} + - {fileID: 1419181043} - {fileID: 2106431002} - {fileID: 116234201} - {fileID: 824396217} diff --git a/Assets/Scripts/DamianExperiments/Minigame/FlashBehaviour.cs b/Assets/Scripts/DamianExperiments/Minigame/FlashBehaviour.cs new file mode 100644 index 00000000..f064a58e --- /dev/null +++ b/Assets/Scripts/DamianExperiments/Minigame/FlashBehaviour.cs @@ -0,0 +1,69 @@ +using UnityEngine; +using System.Collections; + +public class FlashBehaviour : MonoBehaviour +{ + public GameObject square; // Assign in inspector or find in Start + public float flashInDuration = 0.05f; + public float flashOutDuration = 0.2f; + + private Color squareColor; + private Coroutine flashCoroutine; + private SpriteRenderer spriteRenderer; + + void Start() + { + + if (square == null) + square = transform.Find("Square")?.gameObject; + + if (square != null) + spriteRenderer = square.GetComponent(); + + if (spriteRenderer != null) + { + squareColor = spriteRenderer.color; + squareColor.a = 0; + } + + } + + public void TriggerFlash() + { + if (flashCoroutine != null) + StopCoroutine(flashCoroutine); + flashCoroutine = StartCoroutine(FlashRoutine()); + } + + private IEnumerator FlashRoutine() + { + // Fade in + float t = 0; + while (t < flashInDuration) + { + t += Time.deltaTime; + SetAlpha(Mathf.Lerp(0, 1, t / flashInDuration)); + yield return null; + } + SetAlpha(1); + + // Fade out + t = 0; + while (t < flashOutDuration) + { + t += Time.deltaTime; + SetAlpha(Mathf.Lerp(1, 0, t / flashOutDuration)); + yield return null; + } + SetAlpha(0); + } + + private void SetAlpha(float alpha) + { + if (spriteRenderer != null) + { + squareColor.a = alpha; + spriteRenderer.color = squareColor; + } + } +} diff --git a/Assets/Scripts/DamianExperiments/Minigame/FlashBehaviour.cs.meta b/Assets/Scripts/DamianExperiments/Minigame/FlashBehaviour.cs.meta new file mode 100644 index 00000000..95cb93fc --- /dev/null +++ b/Assets/Scripts/DamianExperiments/Minigame/FlashBehaviour.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 194155c0137366c4ea64558d2601e19a \ No newline at end of file diff --git a/Assets/Scripts/Minigames/DivingForPictures/DivingGameManager.cs b/Assets/Scripts/Minigames/DivingForPictures/DivingGameManager.cs index 59ac63d9..a5d82454 100644 --- a/Assets/Scripts/Minigames/DivingForPictures/DivingGameManager.cs +++ b/Assets/Scripts/Minigames/DivingForPictures/DivingGameManager.cs @@ -29,7 +29,12 @@ namespace Minigames.DivingForPictures [Header("Surfacing Settings")] [Tooltip("Reference to the PlayableDirector that will play the surfacing timeline")] [SerializeField] private PlayableDirector surfacingTimeline; - + + [Header("Flash Effect Reference")] + [Tooltip("Reference to the Flash Effect when the picture is taken")] + [SerializeField] private GameObject flashRef; + + private CameraViewfinderManager viewfinderManager; // Settings reference @@ -871,7 +876,19 @@ namespace Minigames.DivingForPictures // Calculate score based on proximity and depth CalculateScore(_currentPhotoTarget, _capturedProximity); - + + //Trigger the Flash Effect + if (flashRef != null) + { + + var flash = flashRef.GetComponent(); + if (flash != null) + { + + flash.TriggerFlash(); + } + } + // Complete the sequence CompletePhotoSequence(); }