From b2384269e5c46295eab9c8498d1649baf2189aa3 Mon Sep 17 00:00:00 2001 From: Michal Pikulski Date: Thu, 16 Oct 2025 23:19:33 +0200 Subject: [PATCH] Update the Pause menu flow to be slightly less scoffed --- .../Scenes/MiniGames/DivingForPictures.unity | 52 +++--- .../Bubbles/BubbleSpawner.cs | 11 +- .../Obstacles/ObstacleSpawner.cs | 9 +- .../Player/PlayerCollisionBehavior.cs | 1 + .../Player/PlayerController.cs | 156 ++++++++++++------ .../Tiles/TrenchTileSpawner.cs | 13 +- .../Utilities/BottlePauser.cs | 2 +- .../DivingForPictures/Utilities/RockPauser.cs | 2 +- Assets/Scripts/UI/DivingGameOverScreen.cs | 8 +- Assets/Scripts/UI/PauseMenu.cs | 3 +- Assets/Settings/DivingMinigameSettings.asset | 2 +- 11 files changed, 167 insertions(+), 92 deletions(-) diff --git a/Assets/Scenes/MiniGames/DivingForPictures.unity b/Assets/Scenes/MiniGames/DivingForPictures.unity index dc3344d5..aba522db 100644 --- a/Assets/Scenes/MiniGames/DivingForPictures.unity +++ b/Assets/Scenes/MiniGames/DivingForPictures.unity @@ -347,12 +347,12 @@ LineRenderer: - {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.5749545, z: 0} - - {x: -0.15968299, y: 3.4769197, z: 0} - - {x: -0.16029257, y: 3.379539, z: 0} - - {x: -0.16090216, y: 3.2828128, z: 0} - - {x: -0.16151173, y: 3.186741, z: 0} - - {x: -0.16212131, y: 3.0913236, 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 widthMultiplier: 1 @@ -1368,16 +1368,16 @@ LineRenderer: m_SortingOrder: 0 m_Positions: - {x: -0.15602553, y: 4.074945, z: 0} - - {x: -0.11662118, y: 3.8796227, z: 0} - - {x: -0.07721684, y: 3.7057447, z: 0} - - {x: -0.03781248, y: 3.553311, z: 0} - - {x: 0.0015918687, y: 3.4223218, z: 0} - - {x: 0.040996216, y: 3.3127768, 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.0890408, z: 0} - - {x: 0.23801796, y: 3.0867176, z: 0} + - {x: -0.11662118, y: 3.8796225, 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.1128078, z: 0} + - {x: 0.1986136, y: 3.0890403, z: 0} + - {x: 0.23801796, y: 3.0867171, z: 0} m_Parameters: serializedVersion: 3 widthMultiplier: 1 @@ -1912,15 +1912,15 @@ LineRenderer: m_Positions: - {x: -0.15602553, y: 4.074945, z: 0} - {x: -0.18956745, y: 3.8764977, z: 0} - - {x: -0.22310936, y: 3.7000237, z: 0} - - {x: -0.25665125, y: 3.5455213, z: 0} - - {x: -0.29019317, y: 3.412991, z: 0} - - {x: -0.32373506, y: 3.302434, z: 0} - - {x: -0.35727698, y: 3.2138486, z: 0} - - {x: -0.39081886, y: 3.147236, z: 0} - - {x: -0.4243608, y: 3.1025963, z: 0} - - {x: -0.45790267, y: 3.0799284, z: 0} - - {x: -0.4914446, y: 3.079233, z: 0} + - {x: -0.22310936, y: 3.7000232, 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.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} m_Parameters: serializedVersion: 3 widthMultiplier: 1 @@ -2469,7 +2469,7 @@ Transform: m_GameObject: {fileID: 2106431001} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.165, y: 2.6975174, z: 0} + m_LocalPosition: {x: -0.165, y: 2.697517, z: 0} m_LocalScale: {x: 0.57574, y: 0.57574, z: 0.57574} m_ConstrainProportionsScale: 0 m_Children: diff --git a/Assets/Scripts/Minigames/DivingForPictures/Bubbles/BubbleSpawner.cs b/Assets/Scripts/Minigames/DivingForPictures/Bubbles/BubbleSpawner.cs index 7ce8ba47..bb4219d0 100644 --- a/Assets/Scripts/Minigames/DivingForPictures/Bubbles/BubbleSpawner.cs +++ b/Assets/Scripts/Minigames/DivingForPictures/Bubbles/BubbleSpawner.cs @@ -1,8 +1,10 @@ -using System.Collections; +using System; +using System.Collections; using UnityEngine; using AppleHills.Core.Settings; using AppleHills.Core.Interfaces; using Core; +using Random = UnityEngine.Random; namespace Minigames.DivingForPictures { @@ -65,10 +67,13 @@ namespace Minigames.DivingForPictures SetNextSpawnInterval(); } - void Start() + private void OnEnable() { DivingGameManager.Instance.RegisterPausableComponent(this); - + } + + void Start() + { // Start spawning if not paused StartSpawningCoroutine(); } diff --git a/Assets/Scripts/Minigames/DivingForPictures/Obstacles/ObstacleSpawner.cs b/Assets/Scripts/Minigames/DivingForPictures/Obstacles/ObstacleSpawner.cs index 3f4711d1..2951d759 100644 --- a/Assets/Scripts/Minigames/DivingForPictures/Obstacles/ObstacleSpawner.cs +++ b/Assets/Scripts/Minigames/DivingForPictures/Obstacles/ObstacleSpawner.cs @@ -83,13 +83,16 @@ namespace Minigames.DivingForPictures onObstacleDestroyed = new UnityEvent(); } + void OnEnable() + { + // Register with the DivingGameManager for pause/resume events + DivingGameManager.Instance.RegisterPausableComponent(this); + } + private void Start() { DivingGameManager.Instance.OnGameInitialized += Initialize; - // Register with the DivingGameManager for pause/resume events - DivingGameManager.Instance.RegisterPausableComponent(this); - // If game is already initialized, initialize immediately if (DivingGameManager.Instance.GetType().GetField("_isGameInitialized", System.Reflection.BindingFlags.NonPublic | diff --git a/Assets/Scripts/Minigames/DivingForPictures/Player/PlayerCollisionBehavior.cs b/Assets/Scripts/Minigames/DivingForPictures/Player/PlayerCollisionBehavior.cs index 7e325f2c..c1a0f333 100644 --- a/Assets/Scripts/Minigames/DivingForPictures/Player/PlayerCollisionBehavior.cs +++ b/Assets/Scripts/Minigames/DivingForPictures/Player/PlayerCollisionBehavior.cs @@ -4,6 +4,7 @@ using System.Collections; using AppleHills.Core.Settings; using AppleHills.Utilities; using Core; +using Minigames.DivingForPictures.Player; namespace Minigames.DivingForPictures { diff --git a/Assets/Scripts/Minigames/DivingForPictures/Player/PlayerController.cs b/Assets/Scripts/Minigames/DivingForPictures/Player/PlayerController.cs index 7a88581a..0e3b24ad 100644 --- a/Assets/Scripts/Minigames/DivingForPictures/Player/PlayerController.cs +++ b/Assets/Scripts/Minigames/DivingForPictures/Player/PlayerController.cs @@ -1,54 +1,59 @@ -using AppleHills.Core.Settings; +using AppleHills.Core.Interfaces; +using AppleHills.Core.Settings; using AppleHillsCamera; -using Cinematics; using Core; using Input; -using UnityEditor.Search; using UnityEngine; -namespace Minigames.DivingForPictures +namespace Minigames.DivingForPictures.Player { /// /// Handles endless descender movement in response to tap and hold input events. /// Moves the character horizontally to follow the finger or tap position. /// - public class PlayerController : MonoBehaviour, ITouchInputConsumer + public class PlayerController : MonoBehaviour, ITouchInputConsumer, IPausable { [Tooltip("Reference to the edge anchor that this player should follow for Y position")] [SerializeField] private EdgeAnchor edgeAnchor; // Settings reference - private IDivingMinigameSettings _settings; + private IDivingMinigameSettings settings; - private float _targetFingerX; - private bool _isTouchActive; - private float _originY; + private float targetFingerX; + private bool isTouchActive; + private float originY; // Tap impulse system variables - private float _tapImpulseStrength = 0f; - private float _tapDirection = 0f; + private float tapImpulseStrength = 0f; + private float tapDirection = 0f; // Initialization flag - private bool _isInitialized = false; + private bool isInitialized = false; void Awake() { - _originY = transform.position.y; + originY = transform.position.y; // Get settings from GameManager - _settings = GameManager.GetSettingsObject(); - if (_settings == null) + settings = GameManager.GetSettingsObject(); + if (settings == null) { Debug.LogError("[PlayerController] Failed to load diving minigame settings!"); } } + void OnEnable() + { + // Register as a pausable component with DivingGameManager + DivingGameManager.Instance.RegisterPausableComponent(this); + } + void Start() { // Initialize target to current position - _targetFingerX = transform.position.x; - _isTouchActive = false; + targetFingerX = transform.position.x; + isTouchActive = false; // Try to find edge anchor if not assigned if (edgeAnchor == null) @@ -59,7 +64,7 @@ namespace Minigames.DivingForPictures // If not found, find any edge anchor in the scene if (edgeAnchor == null) { - edgeAnchor = FindObjectOfType(); + edgeAnchor = FindFirstObjectByType(); if (edgeAnchor == null) { Logging.Warning("[PlayerController] No EdgeAnchor found in scene. Origin Y position won't update with camera changes."); @@ -98,12 +103,12 @@ namespace Minigames.DivingForPictures /// private void Initialize() { - if (_isInitialized) return; + if (isInitialized) return; // Register as default consumer for input InputManager.Instance?.SetDefaultConsumer(this); - _isInitialized = true; + isInitialized = true; Logging.Debug("[PlayerController] Initialized"); } @@ -111,6 +116,9 @@ namespace Minigames.DivingForPictures { DivingGameManager.Instance.OnGameInitialized -= Initialize; + // Unregister as a pausable component + DivingGameManager.Instance.UnregisterPausableComponent(this); + // Unsubscribe from edge anchor events if (edgeAnchor != null) { @@ -123,17 +131,20 @@ namespace Minigames.DivingForPictures /// public void OnTap(Vector2 worldPosition) { + // Ignore input when paused + if (isPaused) return; + // Logging.Debug($"[EndlessDescenderController] OnTap at {worldPosition}"); - float targetX = Mathf.Clamp(worldPosition.x, _settings.ClampXMin, _settings.ClampXMax); + float targetX = Mathf.Clamp(worldPosition.x, settings.ClampXMin, settings.ClampXMax); // Calculate tap direction (+1 for right, -1 for left) - _tapDirection = Mathf.Sign(targetX - transform.position.x); + tapDirection = Mathf.Sign(targetX - transform.position.x); // Set impulse strength to full - _tapImpulseStrength = 1.0f; + tapImpulseStrength = 1.0f; // Store target X for animation purposes - _targetFingerX = targetX; + targetFingerX = targetX; // Do not set _isTouchActive for taps anymore // _isTouchActive = true; - Removed to prevent continuous movement @@ -144,9 +155,12 @@ namespace Minigames.DivingForPictures /// public void OnHoldStart(Vector2 worldPosition) { + // Ignore input when paused + if (isPaused) return; + // Logging.Debug($"[EndlessDescenderController] OnHoldStart at {worldPosition}"); - _targetFingerX = Mathf.Clamp(worldPosition.x, _settings.ClampXMin, _settings.ClampXMax); - _isTouchActive = true; + targetFingerX = Mathf.Clamp(worldPosition.x, settings.ClampXMin, settings.ClampXMax); + isTouchActive = true; } /// @@ -154,8 +168,11 @@ namespace Minigames.DivingForPictures /// public void OnHoldMove(Vector2 worldPosition) { + // Ignore input when paused + if (isPaused) return; + // Logging.Debug($"[EndlessDescenderController] OnHoldMove at {worldPosition}"); - _targetFingerX = Mathf.Clamp(worldPosition.x, _settings.ClampXMin, _settings.ClampXMax); + targetFingerX = Mathf.Clamp(worldPosition.x, settings.ClampXMin, settings.ClampXMax); } /// @@ -163,20 +180,26 @@ namespace Minigames.DivingForPictures /// public void OnHoldEnd(Vector2 worldPosition) { + // Ignore input when paused + if (isPaused) return; + // Logging.Debug($"[EndlessDescenderController] OnHoldEnd at {worldPosition}"); - _isTouchActive = false; + isTouchActive = false; } void Update() { + // Skip movement processing if paused + if (isPaused) return; + // Handle hold movement - if (_isTouchActive) + if (isTouchActive) { float currentX = transform.position.x; - float lerpSpeed = _settings.LerpSpeed; - float maxOffset = _settings.MaxOffset; - float exponent = _settings.SpeedExponent; - float targetX = _targetFingerX; + float lerpSpeed = settings.LerpSpeed; + float maxOffset = settings.MaxOffset; + float exponent = settings.SpeedExponent; + float targetX = targetFingerX; float offset = targetX - currentX; offset = Mathf.Clamp(offset, -maxOffset, maxOffset); float absOffset = Mathf.Abs(offset); @@ -185,32 +208,32 @@ namespace Minigames.DivingForPictures // Prevent overshooting moveStep = Mathf.Clamp(moveStep, -absOffset, absOffset); float newX = currentX + moveStep; - newX = Mathf.Clamp(newX, _settings.ClampXMin, _settings.ClampXMax); + newX = Mathf.Clamp(newX, settings.ClampXMin, settings.ClampXMax); UpdatePosition(newX); } // Handle tap impulse movement - else if (_tapImpulseStrength > 0) + else if (tapImpulseStrength > 0) { float currentX = transform.position.x; - float maxOffset = _settings.MaxOffset; - float lerpSpeed = _settings.LerpSpeed; + float maxOffset = settings.MaxOffset; + float lerpSpeed = settings.LerpSpeed; // Calculate move distance based on impulse strength - float moveDistance = maxOffset * _tapImpulseStrength * Time.deltaTime * lerpSpeed; + float moveDistance = maxOffset * tapImpulseStrength * Time.deltaTime * lerpSpeed; // Limit total movement from single tap - moveDistance = Mathf.Min(moveDistance, _settings.TapMaxDistance * _tapImpulseStrength); + moveDistance = Mathf.Min(moveDistance, settings.TapMaxDistance * tapImpulseStrength); // Apply movement in tap direction - float newX = currentX + (moveDistance * _tapDirection); - newX = Mathf.Clamp(newX, _settings.ClampXMin, _settings.ClampXMax); + float newX = currentX + (moveDistance * tapDirection); + newX = Mathf.Clamp(newX, settings.ClampXMin, settings.ClampXMax); // Reduce impulse strength over time - _tapImpulseStrength -= Time.deltaTime * _settings.TapDecelerationRate; - if (_tapImpulseStrength < 0.01f) + tapImpulseStrength -= Time.deltaTime * settings.TapDecelerationRate; + if (tapImpulseStrength < 0.01f) { - _tapImpulseStrength = 0f; + tapImpulseStrength = 0f; } UpdatePosition(newX); @@ -222,7 +245,7 @@ namespace Minigames.DivingForPictures /// private void UpdatePosition(float newX) { - float newY = _originY; + float newY = originY; // Add vertical offset from WobbleBehavior if present WobbleBehavior wobble = GetComponent(); if (wobble != null) @@ -237,7 +260,7 @@ namespace Minigames.DivingForPictures /// public void UpdateOriginY(float newOriginY) { - _originY = newOriginY; + originY = newOriginY; } /// @@ -246,7 +269,7 @@ namespace Minigames.DivingForPictures /// private void UpdateOriginYFromCurrentPosition() { - _originY = transform.position.y; + originY = transform.position.y; } /// @@ -255,8 +278,43 @@ namespace Minigames.DivingForPictures /// private void UpdateOriginYFromAnchor() { - _originY = edgeAnchor.transform.position.y; + originY = edgeAnchor.transform.position.y; } + #region IPausable Implementation + private bool isPaused = false; + + /// + /// Pauses the player controller, blocking all input processing + /// + public void Pause() + { + if (isPaused) return; + + isPaused = true; + + // If we're being paused, stop any active touch and tap impulse + isTouchActive = false; + tapImpulseStrength = 0f; + + Logging.Debug("[PlayerController] Paused"); + } + + /// + /// Resumes the player controller, allowing input processing again + /// + public void DoResume() + { + if (!isPaused) return; + + isPaused = false; + Logging.Debug("[PlayerController] Resumed"); + } + + /// + /// Returns whether the player controller is currently paused + /// + public bool IsPaused => isPaused; + #endregion } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Minigames/DivingForPictures/Tiles/TrenchTileSpawner.cs b/Assets/Scripts/Minigames/DivingForPictures/Tiles/TrenchTileSpawner.cs index 9cc88950..1411c075 100644 --- a/Assets/Scripts/Minigames/DivingForPictures/Tiles/TrenchTileSpawner.cs +++ b/Assets/Scripts/Minigames/DivingForPictures/Tiles/TrenchTileSpawner.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; @@ -8,6 +9,7 @@ using AppleHills.Core.Settings; using Utils; using AppleHills.Core.Interfaces; using Core; +using Random = UnityEngine.Random; namespace Minigames.DivingForPictures { @@ -166,13 +168,16 @@ namespace Minigames.DivingForPictures } } + private void OnEnable() + { + // Register with the DivingGameManager for pause/resume events + DivingGameManager.Instance.RegisterPausableComponent(this); + } + private void Start() { DivingGameManager.Instance.OnGameInitialized += Initialize; - // Register with the DivingGameManager for pause/resume events - DivingGameManager.Instance.RegisterPausableComponent(this); - // If game is already initialized, initialize immediately if (DivingGameManager.Instance.GetType().GetField("_isGameInitialized", System.Reflection.BindingFlags.NonPublic | diff --git a/Assets/Scripts/Minigames/DivingForPictures/Utilities/BottlePauser.cs b/Assets/Scripts/Minigames/DivingForPictures/Utilities/BottlePauser.cs index b524057e..9dbf8b2c 100644 --- a/Assets/Scripts/Minigames/DivingForPictures/Utilities/BottlePauser.cs +++ b/Assets/Scripts/Minigames/DivingForPictures/Utilities/BottlePauser.cs @@ -9,7 +9,7 @@ namespace Minigames.DivingForPictures.Utilities private bool isPaused = false; - private void Awake() + private void OnEnable() { DivingGameManager.Instance.RegisterPausableComponent(this); } diff --git a/Assets/Scripts/Minigames/DivingForPictures/Utilities/RockPauser.cs b/Assets/Scripts/Minigames/DivingForPictures/Utilities/RockPauser.cs index 5d09a221..d9ca7fc1 100644 --- a/Assets/Scripts/Minigames/DivingForPictures/Utilities/RockPauser.cs +++ b/Assets/Scripts/Minigames/DivingForPictures/Utilities/RockPauser.cs @@ -10,7 +10,7 @@ namespace Minigames.DivingForPictures.Utilities private bool isPaused = false; - private void Awake() + private void OnEnable() { DivingGameManager.Instance.RegisterPausableComponent(this); } diff --git a/Assets/Scripts/UI/DivingGameOverScreen.cs b/Assets/Scripts/UI/DivingGameOverScreen.cs index da09bb7d..48c74004 100644 --- a/Assets/Scripts/UI/DivingGameOverScreen.cs +++ b/Assets/Scripts/UI/DivingGameOverScreen.cs @@ -1,3 +1,4 @@ +using System; using Core; using UnityEngine; using UnityEngine.SceneManagement; @@ -10,9 +11,10 @@ public class DivingGameOverScreen : MonoBehaviour } - public void PlayAgain() + public async void PlayAgain() { - SceneManagerService.Instance.ReloadCurrentScene(); + var progress = new Progress(p => Logging.Debug($"Loading progress: {p * 100:F0}%")); + await SceneManagerService.Instance.ReloadCurrentScene(progress);; gameObject.SetActive(false); } -} +} \ No newline at end of file diff --git a/Assets/Scripts/UI/PauseMenu.cs b/Assets/Scripts/UI/PauseMenu.cs index 55f132e0..18a206c5 100644 --- a/Assets/Scripts/UI/PauseMenu.cs +++ b/Assets/Scripts/UI/PauseMenu.cs @@ -124,7 +124,8 @@ namespace UI // Clear paused flag and broadcast event _isPaused = false; InputManager.Instance.SetInputMode(InputMode.GameAndUI); - OnGameResumed?.Invoke(); + if(resetInput) + OnGameResumed?.Invoke(); Logging.Debug("[PauseMenu] Game Resumed"); } diff --git a/Assets/Settings/DivingMinigameSettings.asset b/Assets/Settings/DivingMinigameSettings.asset index 8fe16611..e337c768 100644 --- a/Assets/Settings/DivingMinigameSettings.asset +++ b/Assets/Settings/DivingMinigameSettings.asset @@ -17,7 +17,7 @@ MonoBehaviour: clampXMin: -3.5 clampXMax: 3.5 speedExponent: 0.97 - tapMaxDistance: 0.2 + tapMaxDistance: 0.03 tapDecelerationRate: 15 baseSpawnProbability: 0.2 maxSpawnProbability: 0.8