Update the Pause menu flow to be slightly less scoffed
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 |
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections;
|
||||
using AppleHills.Core.Settings;
|
||||
using AppleHills.Utilities;
|
||||
using Core;
|
||||
using Minigames.DivingForPictures.Player;
|
||||
|
||||
namespace Minigames.DivingForPictures
|
||||
{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 |
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Minigames.DivingForPictures.Utilities
|
||||
|
||||
private bool isPaused = false;
|
||||
|
||||
private void Awake()
|
||||
private void OnEnable()
|
||||
{
|
||||
DivingGameManager.Instance.RegisterPausableComponent(this);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Minigames.DivingForPictures.Utilities
|
||||
|
||||
private bool isPaused = false;
|
||||
|
||||
private void Awake()
|
||||
private void OnEnable()
|
||||
{
|
||||
DivingGameManager.Instance.RegisterPausableComponent(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user