IMplement basic Developer Settings
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using AppleHills.Core.Settings;
|
||||
|
||||
namespace Minigames.DivingForPictures
|
||||
{
|
||||
@@ -8,11 +9,8 @@ namespace Minigames.DivingForPictures
|
||||
/// </summary>
|
||||
public class PlayerController : MonoBehaviour, ITouchInputConsumer
|
||||
{
|
||||
[Header("Tap Movement")]
|
||||
[Tooltip("Maximum distance the player can move from a single tap")]
|
||||
[SerializeField] private float tapMaxDistance = 0.5f;
|
||||
[Tooltip("How quickly the tap impulse fades (higher = faster stop)")]
|
||||
[SerializeField] private float tapDecelerationRate = 5.0f;
|
||||
// Settings reference
|
||||
private IDivingMinigameSettings _settings;
|
||||
|
||||
private float _targetFingerX;
|
||||
private bool _isTouchActive;
|
||||
@@ -25,6 +23,13 @@ namespace Minigames.DivingForPictures
|
||||
void Awake()
|
||||
{
|
||||
_originY = transform.position.y;
|
||||
|
||||
// Get settings from GameManager
|
||||
_settings = GameManager.GetSettingsObject<IDivingMinigameSettings>();
|
||||
if (_settings == null)
|
||||
{
|
||||
Debug.LogError("[PlayerController] Failed to load diving minigame settings!");
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
@@ -42,7 +47,7 @@ namespace Minigames.DivingForPictures
|
||||
public void OnTap(Vector2 worldPosition)
|
||||
{
|
||||
// Debug.Log($"[EndlessDescenderController] OnTap at {worldPosition}");
|
||||
float targetX = Mathf.Clamp(worldPosition.x, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
|
||||
float targetX = Mathf.Clamp(worldPosition.x, _settings.EndlessDescenderClampXMin, _settings.EndlessDescenderClampXMax);
|
||||
|
||||
// Calculate tap direction (+1 for right, -1 for left)
|
||||
_tapDirection = Mathf.Sign(targetX - transform.position.x);
|
||||
@@ -63,7 +68,7 @@ namespace Minigames.DivingForPictures
|
||||
public void OnHoldStart(Vector2 worldPosition)
|
||||
{
|
||||
// Debug.Log($"[EndlessDescenderController] OnHoldStart at {worldPosition}");
|
||||
_targetFingerX = Mathf.Clamp(worldPosition.x, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
|
||||
_targetFingerX = Mathf.Clamp(worldPosition.x, _settings.EndlessDescenderClampXMin, _settings.EndlessDescenderClampXMax);
|
||||
_isTouchActive = true;
|
||||
}
|
||||
|
||||
@@ -73,7 +78,7 @@ namespace Minigames.DivingForPictures
|
||||
public void OnHoldMove(Vector2 worldPosition)
|
||||
{
|
||||
// Debug.Log($"[EndlessDescenderController] OnHoldMove at {worldPosition}");
|
||||
_targetFingerX = Mathf.Clamp(worldPosition.x, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
|
||||
_targetFingerX = Mathf.Clamp(worldPosition.x, _settings.EndlessDescenderClampXMin, _settings.EndlessDescenderClampXMax);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -91,9 +96,9 @@ namespace Minigames.DivingForPictures
|
||||
if (_isTouchActive)
|
||||
{
|
||||
float currentX = transform.position.x;
|
||||
float lerpSpeed = GameManager.Instance.EndlessDescenderLerpSpeed;
|
||||
float maxOffset = GameManager.Instance.EndlessDescenderMaxOffset;
|
||||
float exponent = GameManager.Instance.EndlessDescenderSpeedExponent;
|
||||
float lerpSpeed = _settings.EndlessDescenderLerpSpeed;
|
||||
float maxOffset = _settings.EndlessDescenderMaxOffset;
|
||||
float exponent = _settings.EndlessDescenderSpeedExponent;
|
||||
float targetX = _targetFingerX;
|
||||
float offset = targetX - currentX;
|
||||
offset = Mathf.Clamp(offset, -maxOffset, maxOffset);
|
||||
@@ -103,7 +108,7 @@ namespace Minigames.DivingForPictures
|
||||
// Prevent overshooting
|
||||
moveStep = Mathf.Clamp(moveStep, -absOffset, absOffset);
|
||||
float newX = currentX + moveStep;
|
||||
newX = Mathf.Clamp(newX, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
|
||||
newX = Mathf.Clamp(newX, _settings.EndlessDescenderClampXMin, _settings.EndlessDescenderClampXMax);
|
||||
|
||||
UpdatePosition(newX);
|
||||
}
|
||||
@@ -111,21 +116,21 @@ namespace Minigames.DivingForPictures
|
||||
else if (_tapImpulseStrength > 0)
|
||||
{
|
||||
float currentX = transform.position.x;
|
||||
float maxOffset = GameManager.Instance.EndlessDescenderMaxOffset;
|
||||
float lerpSpeed = GameManager.Instance.EndlessDescenderLerpSpeed;
|
||||
float maxOffset = _settings.EndlessDescenderMaxOffset;
|
||||
float lerpSpeed = _settings.EndlessDescenderLerpSpeed;
|
||||
|
||||
// Calculate move distance based on impulse strength
|
||||
float moveDistance = maxOffset * _tapImpulseStrength * Time.deltaTime * lerpSpeed;
|
||||
|
||||
// Limit total movement from single tap
|
||||
moveDistance = Mathf.Min(moveDistance, tapMaxDistance * _tapImpulseStrength);
|
||||
moveDistance = Mathf.Min(moveDistance, _settings.EndlessDescenderTapMaxDistance * _tapImpulseStrength);
|
||||
|
||||
// Apply movement in tap direction
|
||||
float newX = currentX + (moveDistance * _tapDirection);
|
||||
newX = Mathf.Clamp(newX, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax);
|
||||
newX = Mathf.Clamp(newX, _settings.EndlessDescenderClampXMin, _settings.EndlessDescenderClampXMax);
|
||||
|
||||
// Reduce impulse strength over time
|
||||
_tapImpulseStrength -= Time.deltaTime * tapDecelerationRate;
|
||||
_tapImpulseStrength -= Time.deltaTime * _settings.EndlessDescenderTapDecelerationRate;
|
||||
if (_tapImpulseStrength < 0.01f)
|
||||
{
|
||||
_tapImpulseStrength = 0f;
|
||||
|
||||
Reference in New Issue
Block a user