Update the Pause menu flow to be slightly less scoffed

This commit is contained in:
Michal Pikulski
2025-10-16 23:19:33 +02:00
parent 09ae4b5ba7
commit b2384269e5
11 changed files with 167 additions and 92 deletions

View File

@@ -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:

View File

@@ -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();
}

View File

@@ -83,13 +83,16 @@ namespace Minigames.DivingForPictures
onObstacleDestroyed = new UnityEvent<GameObject>();
}
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 |

View File

@@ -4,6 +4,7 @@ using System.Collections;
using AppleHills.Core.Settings;
using AppleHills.Utilities;
using Core;
using Minigames.DivingForPictures.Player;
namespace Minigames.DivingForPictures
{

View File

@@ -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
{
/// <summary>
/// Handles endless descender movement in response to tap and hold input events.
/// Moves the character horizontally to follow the finger or tap position.
/// </summary>
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<IDivingMinigameSettings>();
if (_settings == null)
settings = GameManager.GetSettingsObject<IDivingMinigameSettings>();
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>();
edgeAnchor = FindFirstObjectByType<EdgeAnchor>();
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
/// </summary>
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
/// </summary>
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
/// </summary>
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;
}
/// <summary>
@@ -154,8 +168,11 @@ namespace Minigames.DivingForPictures
/// </summary>
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);
}
/// <summary>
@@ -163,20 +180,26 @@ namespace Minigames.DivingForPictures
/// </summary>
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
/// </summary>
private void UpdatePosition(float newX)
{
float newY = _originY;
float newY = originY;
// Add vertical offset from WobbleBehavior if present
WobbleBehavior wobble = GetComponent<WobbleBehavior>();
if (wobble != null)
@@ -237,7 +260,7 @@ namespace Minigames.DivingForPictures
/// </summary>
public void UpdateOriginY(float newOriginY)
{
_originY = newOriginY;
originY = newOriginY;
}
/// <summary>
@@ -246,7 +269,7 @@ namespace Minigames.DivingForPictures
/// </summary>
private void UpdateOriginYFromCurrentPosition()
{
_originY = transform.position.y;
originY = transform.position.y;
}
/// <summary>
@@ -255,8 +278,43 @@ namespace Minigames.DivingForPictures
/// </summary>
private void UpdateOriginYFromAnchor()
{
_originY = edgeAnchor.transform.position.y;
originY = edgeAnchor.transform.position.y;
}
#region IPausable Implementation
private bool isPaused = false;
/// <summary>
/// Pauses the player controller, blocking all input processing
/// </summary>
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");
}
/// <summary>
/// Resumes the player controller, allowing input processing again
/// </summary>
public void DoResume()
{
if (!isPaused) return;
isPaused = false;
Logging.Debug("[PlayerController] Resumed");
}
/// <summary>
/// Returns whether the player controller is currently paused
/// </summary>
public bool IsPaused => isPaused;
#endregion
}
}

View File

@@ -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 |

View File

@@ -9,7 +9,7 @@ namespace Minigames.DivingForPictures.Utilities
private bool isPaused = false;
private void Awake()
private void OnEnable()
{
DivingGameManager.Instance.RegisterPausableComponent(this);
}

View File

@@ -10,7 +10,7 @@ namespace Minigames.DivingForPictures.Utilities
private bool isPaused = false;
private void Awake()
private void OnEnable()
{
DivingGameManager.Instance.RegisterPausableComponent(this);
}

View File

@@ -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<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
await SceneManagerService.Instance.ReloadCurrentScene(progress);;
gameObject.SetActive(false);
}
}

View File

@@ -124,6 +124,7 @@ namespace UI
// Clear paused flag and broadcast event
_isPaused = false;
InputManager.Instance.SetInputMode(InputMode.GameAndUI);
if(resetInput)
OnGameResumed?.Invoke();
Logging.Debug("[PauseMenu] Game Resumed");

View File

@@ -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