Compare commits

..

2 Commits

Author SHA1 Message Date
Michal Pikulski
0b966e9976 Working screen anchoring 2025-10-13 16:31:52 +02:00
Michal Pikulski
a55ba5e29c First steps with camera framing 2025-10-13 15:34:07 +02:00
8 changed files with 19 additions and 173 deletions

View File

@@ -139,10 +139,6 @@ namespace AppleHills.Core.Settings
[Tooltip("Animation curve for the shrinking effect")] [Tooltip("Animation curve for the shrinking effect")]
[SerializeField] private AnimationCurve viewfinderShrinkCurve = AnimationCurve.EaseInOut(0, 1, 1, 0); [SerializeField] private AnimationCurve viewfinderShrinkCurve = AnimationCurve.EaseInOut(0, 1, 1, 0);
[Header("Photo Input")]
[Tooltip("Input mode for photo taking sequence")]
[SerializeField] private PhotoInputModes photoInputMode = PhotoInputModes.Tap;
[Tooltip("Padding factor to add space around the monster (1.0 = exact size, 1.2 = 20% extra)")] [Tooltip("Padding factor to add space around the monster (1.0 = exact size, 1.2 = 20% extra)")]
[SerializeField] private float paddingFactor = 1.2f; [SerializeField] private float paddingFactor = 1.2f;
@@ -224,7 +220,6 @@ namespace AppleHills.Core.Settings
public float PaddingFactor => paddingFactor; public float PaddingFactor => paddingFactor;
public float MaxSizePercent => maxSizePercent; public float MaxSizePercent => maxSizePercent;
public float MinSizePercent => minSizePercent; public float MinSizePercent => minSizePercent;
public PhotoInputModes PhotoInputMode => photoInputMode;
public override void OnValidate() public override void OnValidate()
{ {

View File

@@ -3,15 +3,6 @@ using System.Collections.Generic;
namespace AppleHills.Core.Settings namespace AppleHills.Core.Settings
{ {
/// <summary>
/// Enum defining the different input modes for photo taking
/// </summary>
public enum PhotoInputModes
{
Tap, // Original tap-based input
Hold // New hold-based input
}
/// <summary> /// <summary>
/// Interface for player and follower settings /// Interface for player and follower settings
/// </summary> /// </summary>
@@ -123,12 +114,11 @@ namespace AppleHills.Core.Settings
float ViewfinderShrinkDuration { get; } float ViewfinderShrinkDuration { get; }
float ViewfinderMoveSpeed { get; } float ViewfinderMoveSpeed { get; }
AnimationCurve ViewfinderShrinkCurve { get; } AnimationCurve ViewfinderShrinkCurve { get; }
float ViewfinderStartScale { get; }
float ViewfinderEndScale { get; }
float[] ViewfinderProgressThresholds { get; } float[] ViewfinderProgressThresholds { get; }
float PaddingFactor { get; } float PaddingFactor { get; }
float MaxSizePercent { get; } float MaxSizePercent { get; }
float MinSizePercent { get; } float MinSizePercent { get; }
// Photo Input Settings
PhotoInputModes PhotoInputMode { get; }
} }
} }

View File

@@ -123,7 +123,6 @@ namespace LevelS
private void OnMenuCancel() private void OnMenuCancel()
{ {
_isActive = true; // Allow interaction again if cancelled _isActive = true; // Allow interaction again if cancelled
InputManager.Instance.SetInputMode(InputMode.GameAndUI);
} }
} }
} }

View File

@@ -294,8 +294,6 @@ namespace Minigames.DivingForPictures
private void SpawnMonster(Transform spawnPoint) private void SpawnMonster(Transform spawnPoint)
{ {
Debug.Log("Spawning monster: " + spawnPoint.name);
if (monsterPrefabs.Length == 0) if (monsterPrefabs.Length == 0)
{ {
Debug.LogWarning("No monster prefabs assigned to DivingGameManager."); Debug.LogWarning("No monster prefabs assigned to DivingGameManager.");

View File

@@ -29,8 +29,6 @@ namespace Minigames.DivingForPictures
private void Awake() private void Awake()
{ {
Debug.Log("Monster created: " + gameObject.name);
if (detectionCollider == null) if (detectionCollider == null)
detectionCollider = GetComponent<CircleCollider2D>(); detectionCollider = GetComponent<CircleCollider2D>();
@@ -46,11 +44,6 @@ namespace Minigames.DivingForPictures
photoSequenceInProgress = false; photoSequenceInProgress = false;
} }
private void OnDestroy()
{
Debug.Log("Monster destroyed: " + gameObject.name);
}
private IEnumerator CheckIfOffScreen() private IEnumerator CheckIfOffScreen()
{ {
WaitForSeconds wait = new WaitForSeconds(0.5f); WaitForSeconds wait = new WaitForSeconds(0.5f);
@@ -79,24 +72,15 @@ namespace Minigames.DivingForPictures
Vector3 worldPosition = transform.position; Vector3 worldPosition = transform.position;
Vector3 viewportPoint = mainCamera.WorldToViewportPoint(worldPosition); Vector3 viewportPoint = mainCamera.WorldToViewportPoint(worldPosition);
// If z is negative, the object is behind the camera // Adjust buffer to be larger below the screen to account for downward movement
if (viewportPoint.z < 0)
return false;
// Simple logic:
// 1. Allow monsters below the screen (new spawns)
// 2. Despawn monsters only when completely above the top of screen
// 3. Keep monsters that are on screen
// Check if the monster is above the top of the screen
if (viewportPoint.y > 1)
return false; // Monster is completely above screen, destroy it
// Check horizontal bounds (keep moderate buffer so monsters don't disappear at screen edges)
float bufferSides = 0.2f; float bufferSides = 0.2f;
bool withinHorizontalBounds = viewportPoint.x > -bufferSides && viewportPoint.x < 1 + bufferSides; float bufferTop = 0.2f;
float bufferBottom = 0.5f; // Larger buffer below the screen
return withinHorizontalBounds; return viewportPoint.x > -bufferSides &&
viewportPoint.x < 1 + bufferSides &&
viewportPoint.y > -bufferBottom &&
viewportPoint.y < 1 + bufferTop;
} }
private void OnTriggerEnter2D(Collider2D other) private void OnTriggerEnter2D(Collider2D other)

View File

@@ -58,9 +58,6 @@ namespace Minigames.DivingForPictures.PictureCamera
// Store settings // Store settings
private IDivingMinigameSettings settings; private IDivingMinigameSettings settings;
// New field to store the current input mode
private PhotoInputModes currentInputMode;
// Events for progress milestones // Events for progress milestones
public event Action<float> OnProgressUpdated; // Continuous progress updates (0-1) public event Action<float> OnProgressUpdated; // Continuous progress updates (0-1)
public event Action OnAnimationStarted; public event Action OnAnimationStarted;
@@ -92,9 +89,6 @@ namespace Minigames.DivingForPictures.PictureCamera
{ {
settings = GameManager.GetSettingsObject<IDivingMinigameSettings>(); settings = GameManager.GetSettingsObject<IDivingMinigameSettings>();
mainCamera = UnityEngine.Camera.main; mainCamera = UnityEngine.Camera.main;
// Get the photo input mode from settings
currentInputMode = settings.PhotoInputMode;
} }
/// <summary> /// <summary>
@@ -141,7 +135,7 @@ namespace Minigames.DivingForPictures.PictureCamera
{ {
viewfinderComponent.Initialize(this); viewfinderComponent.Initialize(this);
viewfinderComponent.SetupInputOverride(); viewfinderComponent.SetupInputOverride();
InitializeViewfinder(viewfinderComponent); viewfinderComponent.OnViewfinderTapped += HandleViewfinderTapped;
} }
// Reset state // Reset state
@@ -456,13 +450,10 @@ namespace Minigames.DivingForPictures.PictureCamera
{ {
if (viewfinderInstance != null) if (viewfinderInstance != null)
{ {
// Unsubscribe from all viewfinder events // Unsubscribe from the viewfinder's tap event
if (viewfinderComponent != null) if (viewfinderComponent != null)
{ {
viewfinderComponent.OnViewfinderTapped -= HandleViewfinderTapped; viewfinderComponent.OnViewfinderTapped -= HandleViewfinderTapped;
viewfinderComponent.OnViewfinderTapped -= HandleViewfinderTappedDuringAnimation;
viewfinderComponent.OnViewfinderHoldStarted -= HandleViewfinderHoldStarted;
viewfinderComponent.OnViewfinderHoldEnded -= HandleViewfinderHoldEnded;
} }
Destroy(viewfinderInstance); Destroy(viewfinderInstance);
@@ -516,7 +507,8 @@ namespace Minigames.DivingForPictures.PictureCamera
{ {
viewfinderComponent.Initialize(this); viewfinderComponent.Initialize(this);
viewfinderComponent.SetupInputOverride(); viewfinderComponent.SetupInputOverride();
InitializeViewfinder(viewfinderComponent); viewfinderComponent.OnViewfinderTapped += HandleViewfinderTapped;
} }
// Determine canvas width for full-screen sizing // Determine canvas width for full-screen sizing
@@ -591,20 +583,6 @@ namespace Minigames.DivingForPictures.PictureCamera
viewfinderComponent.OnViewfinderTapped += HandleViewfinderTappedDuringAnimation; viewfinderComponent.OnViewfinderTapped += HandleViewfinderTappedDuringAnimation;
} }
// Initialize viewfinder with appropriate event handlers based on input mode
if (viewfinderComponent != null)
{
viewfinderComponent.Initialize(this);
viewfinderComponent.SetupInputOverride();
InitializeViewfinder(viewfinderComponent);
// For animation sequence, we need additional handling for tapping during animation
if (currentInputMode == PhotoInputModes.Tap)
{
viewfinderComponent.OnViewfinderTapped += HandleViewfinderTappedDuringAnimation;
}
}
// Reset state // Reset state
animationProgress = 0f; animationProgress = 0f;
isAnimating = true; isAnimating = true;
@@ -794,80 +772,5 @@ namespace Minigames.DivingForPictures.PictureCamera
HandleViewfinderTapped(); HandleViewfinderTapped();
} }
} }
/// <summary>
/// Initialize the viewfinder with appropriate event handlers based on input mode
/// </summary>
/// <param name="viewfinder">The viewfinder component to initialize</param>
public void InitializeViewfinder(Viewfinder viewfinder)
{
if (viewfinder != null)
{
// Clean up any existing event subscriptions
viewfinder.OnViewfinderTapped -= HandleViewfinderTapped;
viewfinder.OnViewfinderHoldStarted -= HandleViewfinderHoldStarted;
viewfinder.OnViewfinderHoldEnded -= HandleViewfinderHoldEnded;
// Set up handlers based on the current input mode
switch (currentInputMode)
{
case PhotoInputModes.Tap:
// For tap mode, only subscribe to tap events
viewfinder.OnViewfinderTapped += HandleViewfinderTapped;
break;
case PhotoInputModes.Hold:
// For hold mode, subscribe to hold start/end events
viewfinder.OnViewfinderHoldStarted += HandleViewfinderHoldStarted;
viewfinder.OnViewfinderHoldEnded += HandleViewfinderHoldEnded;
break;
}
}
}
/// <summary>
/// Handles hold start event from the viewfinder
/// </summary>
private void HandleViewfinderHoldStarted()
{
if (currentInputMode == PhotoInputModes.Hold)
{
// Start the photo sequence when hold begins (same behavior as first tap in tap mode)
OnViewfinderTapped?.Invoke();
Debug.Log("[CameraViewfinderManager] Hold started - initiating photo sequence");
}
}
/// <summary>
/// Handles hold end event from the viewfinder
/// </summary>
private void HandleViewfinderHoldEnded()
{
if (currentInputMode == PhotoInputModes.Hold && isAnimating)
{
// Complete the sequence when hold ends (same behavior as second tap in tap mode)
OnViewfinderTappedDuringAnimation?.Invoke(currentProximity);
Debug.Log("[CameraViewfinderManager] Hold ended - completing photo sequence with proximity: " + currentProximity);
// Complete the animation immediately
if (animationCoroutine != null)
{
StopCoroutine(animationCoroutine);
animationCoroutine = null;
}
// Fire completed event
OnAnimationCompleted?.Invoke();
isAnimating = false;
isReversePhase = false;
// Hide the viewfinder
if (viewfinderComponent != null)
{
viewfinderComponent.RemoveInputOverride();
}
HideViewfinder();
}
}
} }
} }

View File

@@ -15,8 +15,6 @@ namespace Minigames.DivingForPictures.PictureCamera
// Events // Events
public event System.Action OnViewfinderTapped; public event System.Action OnViewfinderTapped;
public event System.Action OnViewfinderHoldStarted;
public event System.Action OnViewfinderHoldEnded;
// State // State
private bool isActive = true; private bool isActive = true;
@@ -103,30 +101,10 @@ namespace Minigames.DivingForPictures.PictureCamera
} }
} }
public void OnHoldStart(Vector2 position) // Required interface methods (no-op implementations)
{ public void OnHoldStart(Vector2 position) { }
if (isActive) public void OnHoldMove(Vector2 position) { }
{ public void OnHoldEnd(Vector2 position) { }
// Fire the hold start event
OnViewfinderHoldStarted?.Invoke();
Debug.Log($"[MDPI] Viewfinder OnHoldStart: {position}");
}
}
public void OnHoldMove(Vector2 position)
{
// We can use this for any continuous effects during hold if needed in the future
}
public void OnHoldEnd(Vector2 position)
{
if (isActive)
{
// Fire the hold end event
OnViewfinderHoldEnded?.Invoke();
Debug.Log($"[MDPI] Viewfinder OnHoldEnd: {position}");
}
}
#endregion #endregion

View File

@@ -20,7 +20,7 @@ MonoBehaviour:
tapMaxDistance: 0.2 tapMaxDistance: 0.2
tapDecelerationRate: 15 tapDecelerationRate: 15
baseSpawnProbability: 0.2 baseSpawnProbability: 0.2
maxSpawnProbability: 0.8 maxSpawnProbability: 0.5
probabilityIncreaseRate: 0.01 probabilityIncreaseRate: 0.01
guaranteedSpawnTime: 30 guaranteedSpawnTime: 30
spawnCooldown: 5 spawnCooldown: 5
@@ -76,7 +76,6 @@ MonoBehaviour:
m_PreInfinity: 2 m_PreInfinity: 2
m_PostInfinity: 2 m_PostInfinity: 2
m_RotationOrder: 4 m_RotationOrder: 4
photoInputMode: 1
paddingFactor: 2 paddingFactor: 2
minSizePercent: 0.15 minSizePercent: 0.15
maxSizePercent: 1 maxSizePercent: 1