photo_input_switch (#27)
Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: #27
This commit is contained in:
@@ -294,6 +294,8 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
private void SpawnMonster(Transform spawnPoint)
|
||||
{
|
||||
Debug.Log("Spawning monster: " + spawnPoint.name);
|
||||
|
||||
if (monsterPrefabs.Length == 0)
|
||||
{
|
||||
Debug.LogWarning("No monster prefabs assigned to DivingGameManager.");
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Debug.Log("Monster created: " + gameObject.name);
|
||||
|
||||
if (detectionCollider == null)
|
||||
detectionCollider = GetComponent<CircleCollider2D>();
|
||||
|
||||
@@ -44,6 +46,11 @@ namespace Minigames.DivingForPictures
|
||||
photoSequenceInProgress = false;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
Debug.Log("Monster destroyed: " + gameObject.name);
|
||||
}
|
||||
|
||||
private IEnumerator CheckIfOffScreen()
|
||||
{
|
||||
WaitForSeconds wait = new WaitForSeconds(0.5f);
|
||||
@@ -72,15 +79,24 @@ namespace Minigames.DivingForPictures
|
||||
Vector3 worldPosition = transform.position;
|
||||
Vector3 viewportPoint = mainCamera.WorldToViewportPoint(worldPosition);
|
||||
|
||||
// Adjust buffer to be larger below the screen to account for downward movement
|
||||
float bufferSides = 0.2f;
|
||||
float bufferTop = 0.2f;
|
||||
float bufferBottom = 0.5f; // Larger buffer below the screen
|
||||
// If z is negative, the object is behind the camera
|
||||
if (viewportPoint.z < 0)
|
||||
return false;
|
||||
|
||||
return viewportPoint.x > -bufferSides &&
|
||||
viewportPoint.x < 1 + bufferSides &&
|
||||
viewportPoint.y > -bufferBottom &&
|
||||
viewportPoint.y < 1 + bufferTop;
|
||||
// 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;
|
||||
bool withinHorizontalBounds = viewportPoint.x > -bufferSides && viewportPoint.x < 1 + bufferSides;
|
||||
|
||||
return withinHorizontalBounds;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
|
||||
@@ -57,6 +57,9 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
|
||||
// Store settings
|
||||
private IDivingMinigameSettings settings;
|
||||
|
||||
// New field to store the current input mode
|
||||
private PhotoInputModes currentInputMode;
|
||||
|
||||
// Events for progress milestones
|
||||
public event Action<float> OnProgressUpdated; // Continuous progress updates (0-1)
|
||||
@@ -89,6 +92,9 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
{
|
||||
settings = GameManager.GetSettingsObject<IDivingMinigameSettings>();
|
||||
mainCamera = UnityEngine.Camera.main;
|
||||
|
||||
// Get the photo input mode from settings
|
||||
currentInputMode = settings.PhotoInputMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -135,7 +141,7 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
{
|
||||
viewfinderComponent.Initialize(this);
|
||||
viewfinderComponent.SetupInputOverride();
|
||||
viewfinderComponent.OnViewfinderTapped += HandleViewfinderTapped;
|
||||
InitializeViewfinder(viewfinderComponent);
|
||||
}
|
||||
|
||||
// Reset state
|
||||
@@ -450,10 +456,13 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
{
|
||||
if (viewfinderInstance != null)
|
||||
{
|
||||
// Unsubscribe from the viewfinder's tap event
|
||||
// Unsubscribe from all viewfinder events
|
||||
if (viewfinderComponent != null)
|
||||
{
|
||||
viewfinderComponent.OnViewfinderTapped -= HandleViewfinderTapped;
|
||||
viewfinderComponent.OnViewfinderTapped -= HandleViewfinderTappedDuringAnimation;
|
||||
viewfinderComponent.OnViewfinderHoldStarted -= HandleViewfinderHoldStarted;
|
||||
viewfinderComponent.OnViewfinderHoldEnded -= HandleViewfinderHoldEnded;
|
||||
}
|
||||
|
||||
Destroy(viewfinderInstance);
|
||||
@@ -507,8 +516,7 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
{
|
||||
viewfinderComponent.Initialize(this);
|
||||
viewfinderComponent.SetupInputOverride();
|
||||
viewfinderComponent.OnViewfinderTapped += HandleViewfinderTapped;
|
||||
|
||||
InitializeViewfinder(viewfinderComponent);
|
||||
}
|
||||
|
||||
// Determine canvas width for full-screen sizing
|
||||
@@ -583,6 +591,20 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
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
|
||||
animationProgress = 0f;
|
||||
isAnimating = true;
|
||||
@@ -772,5 +794,80 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
|
||||
// Events
|
||||
public event System.Action OnViewfinderTapped;
|
||||
public event System.Action OnViewfinderHoldStarted;
|
||||
public event System.Action OnViewfinderHoldEnded;
|
||||
|
||||
// State
|
||||
private bool isActive = true;
|
||||
@@ -101,10 +103,30 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
}
|
||||
}
|
||||
|
||||
// Required interface methods (no-op implementations)
|
||||
public void OnHoldStart(Vector2 position) { }
|
||||
public void OnHoldMove(Vector2 position) { }
|
||||
public void OnHoldEnd(Vector2 position) { }
|
||||
public void OnHoldStart(Vector2 position)
|
||||
{
|
||||
if (isActive)
|
||||
{
|
||||
// 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user