From e1f62a0fa1437716adf0bbafee77de5db5b05f06 Mon Sep 17 00:00:00 2001 From: Damian Date: Mon, 20 Oct 2025 13:21:57 +0200 Subject: [PATCH] Added a Flash when taking a picture. --- Assets/Art/Materials/Flash.meta | 8 + Assets/Art/Materials/Flash/M_Flash.mat | 34 ++++ Assets/Art/Materials/Flash/M_Flash.mat.meta | 8 + .../Scenes/MiniGames/DivingForPictures.unity | 160 ++++++++++++++++-- .../Minigame/FlashBehaviour.cs | 69 ++++++++ .../Minigame/FlashBehaviour.cs.meta | 2 + .../DivingForPictures/DivingGameManager.cs | 21 ++- 7 files changed, 290 insertions(+), 12 deletions(-) create mode 100644 Assets/Art/Materials/Flash.meta create mode 100644 Assets/Art/Materials/Flash/M_Flash.mat create mode 100644 Assets/Art/Materials/Flash/M_Flash.mat.meta create mode 100644 Assets/Scripts/DamianExperiments/Minigame/FlashBehaviour.cs create mode 100644 Assets/Scripts/DamianExperiments/Minigame/FlashBehaviour.cs.meta diff --git a/Assets/Art/Materials/Flash.meta b/Assets/Art/Materials/Flash.meta new file mode 100644 index 00000000..7fafd585 --- /dev/null +++ b/Assets/Art/Materials/Flash.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b28e08c357e5bf64fb97ebde541a0e61 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Art/Materials/Flash/M_Flash.mat b/Assets/Art/Materials/Flash/M_Flash.mat new file mode 100644 index 00000000..0d8db2cb --- /dev/null +++ b/Assets/Art/Materials/Flash/M_Flash.mat @@ -0,0 +1,34 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: M_Flash + m_Shader: {fileID: 10750, guid: 0000000000000000f000000000000000, type: 0} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: [] + m_Colors: [] + m_BuildTextureStacks: [] + m_AllowLocking: 1 diff --git a/Assets/Art/Materials/Flash/M_Flash.mat.meta b/Assets/Art/Materials/Flash/M_Flash.mat.meta new file mode 100644 index 00000000..cd5384b9 --- /dev/null +++ b/Assets/Art/Materials/Flash/M_Flash.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: abb67d3c034f40b4aa07dec3386c6c71 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/MiniGames/DivingForPictures.unity b/Assets/Scenes/MiniGames/DivingForPictures.unity index 16c69dea..fe0e30c8 100644 --- a/Assets/Scenes/MiniGames/DivingForPictures.unity +++ b/Assets/Scenes/MiniGames/DivingForPictures.unity @@ -649,6 +649,7 @@ MonoBehaviour: - {fileID: 1062017697} - {fileID: 173052728} surfacingTimeline: {fileID: 2064311130} + flashRef: {fileID: 553184965} --- !u!4 &424805726 Transform: m_ObjectHideFlags: 0 @@ -790,6 +791,54 @@ Animator: m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorStateOnDisable: 0 m_WriteDefaultValuesOnDisable: 0 +--- !u!1 &553184965 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 553184968} + - component: {fileID: 553184966} + m_Layer: 0 + m_Name: Flash + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &553184966 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 553184965} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 194155c0137366c4ea64558d2601e19a, type: 3} + m_Name: + m_EditorClassIdentifier: '::' + square: {fileID: 1946128997} + flashInDuration: 0.05 + flashOutDuration: 0.2 +--- !u!4 &553184968 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 553184965} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 6.94, y: 0.26, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 1946128999} + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &730962732 GameObject: m_ObjectHideFlags: 0 @@ -1367,15 +1416,15 @@ LineRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_Positions: - - {x: -0.15602553, y: 4.074945, z: 0} - - {x: -0.11662118, y: 3.8796225, z: 0} + - {x: -0.15602553, y: 4.0749445, z: 0} + - {x: -0.11662118, y: 3.879622, z: 0} - {x: -0.07721684, y: 3.7057445, 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.112808, z: 0} + - {x: 0.08040057, y: 3.2246761, z: 0} + - {x: 0.11980491, y: 3.15802, z: 0} + - {x: 0.15920927, y: 3.1128082, z: 0} - {x: 0.1986136, y: 3.0890405, z: 0} - {x: 0.23801796, y: 3.0867176, z: 0} m_Parameters: @@ -1910,13 +1959,13 @@ LineRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_Positions: - - {x: -0.15602553, y: 4.074945, z: 0} - - {x: -0.18956745, y: 3.8764977, z: 0} + - {x: -0.15602553, y: 4.0749445, z: 0} + - {x: -0.18956745, y: 3.8764973, z: 0} - {x: -0.22310936, y: 3.7000232, z: 0} - - {x: -0.25665125, y: 3.5455208, z: 0} - - {x: -0.29019317, y: 3.4129908, z: 0} + - {x: -0.25665125, y: 3.5455203, z: 0} + - {x: -0.29019317, y: 3.412991, z: 0} - {x: -0.32373506, y: 3.3024335, z: 0} - - {x: -0.35727698, y: 3.213848, z: 0} + - {x: -0.35727698, y: 3.2138484, z: 0} - {x: -0.39081886, y: 3.1472359, z: 0} - {x: -0.4243608, y: 3.1025958, z: 0} - {x: -0.45790267, y: 3.0799282, z: 0} @@ -2318,6 +2367,96 @@ Transform: m_Children: [] m_Father: {fileID: 2106431002} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1946128997 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1946128999} + - component: {fileID: 1946128998} + m_Layer: 0 + m_Name: Square + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!212 &1946128998 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1946128997} + 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 &1946128999 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1946128997} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -7, y: 0, z: 0} + m_LocalScale: {x: 14, y: 18, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 553184968} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1976291907 GameObject: m_ObjectHideFlags: 0 @@ -2600,6 +2739,7 @@ SceneRoots: m_Roots: - {fileID: 1063641114} - {fileID: 224729333} + - {fileID: 553184968} - {fileID: 747976397} - {fileID: 2106431002} - {fileID: 116234201} 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 2725d1c6..2d71777e 100644 --- a/Assets/Scripts/Minigames/DivingForPictures/DivingGameManager.cs +++ b/Assets/Scripts/Minigames/DivingForPictures/DivingGameManager.cs @@ -29,7 +29,11 @@ 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 @@ -866,7 +870,20 @@ 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(); }