154 lines
4.8 KiB
C#
154 lines
4.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Core.Lifecycle;
|
|
using Pixelplacement.TweenSystem;
|
|
using Utils;
|
|
|
|
namespace Minigames.BirdPooper
|
|
{
|
|
/// <summary>
|
|
/// Manages "tap to start" flow for Bird Pooper minigame.
|
|
/// Shows blinking finger UI, waits for first tap, then starts the game.
|
|
/// </summary>
|
|
public class TapToStartController : ManagedBehaviour, ITouchInputConsumer
|
|
{
|
|
[Header("UI References")]
|
|
[SerializeField] private GameObject fingerContainer;
|
|
[SerializeField] private Image fingerImage;
|
|
|
|
[Header("Animation Settings")]
|
|
[Tooltip("Duration for one complete fade in/out cycle")]
|
|
[SerializeField] private float blinkDuration = 1.5f;
|
|
[Tooltip("Minimum alpha value during blink")]
|
|
[SerializeField] private float minAlpha = 0.3f;
|
|
[Tooltip("Maximum alpha value during blink")]
|
|
[SerializeField] private float maxAlpha = 1f;
|
|
|
|
private bool _isWaitingForTap;
|
|
private TweenBase _blinkTween;
|
|
|
|
internal override void OnManagedAwake()
|
|
{
|
|
base.OnManagedAwake();
|
|
|
|
// Validate references
|
|
if (fingerContainer == null)
|
|
{
|
|
Debug.LogError("[TapToStartController] Finger container not assigned!");
|
|
}
|
|
|
|
if (fingerImage == null)
|
|
{
|
|
Debug.LogError("[TapToStartController] Finger image not assigned!");
|
|
}
|
|
|
|
// Start hidden
|
|
if (fingerContainer != null)
|
|
{
|
|
fingerContainer.SetActive(false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Activates the tap-to-start UI and begins waiting for player input.
|
|
/// Called by BirdPooperGameManager when scene is ready.
|
|
/// </summary>
|
|
public void Activate()
|
|
{
|
|
if (_isWaitingForTap)
|
|
{
|
|
Debug.LogWarning("[TapToStartController] Already waiting for tap!");
|
|
return;
|
|
}
|
|
|
|
Debug.Log("[TapToStartController] Activating tap-to-start...");
|
|
|
|
_isWaitingForTap = true;
|
|
|
|
// Show finger UI
|
|
if (fingerContainer != null)
|
|
{
|
|
fingerContainer.SetActive(true);
|
|
}
|
|
|
|
// Start blinking animation using tween utility
|
|
if (fingerImage != null)
|
|
{
|
|
_blinkTween = TweenAnimationUtility.StartBlinkImage(fingerImage, minAlpha, maxAlpha, blinkDuration);
|
|
}
|
|
|
|
// Register as high-priority input consumer to catch first tap
|
|
if (Input.InputManager.Instance != null)
|
|
{
|
|
Input.InputManager.Instance.SetDefaultConsumer(this);
|
|
Debug.Log("[TapToStartController] Registered as input consumer");
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("[TapToStartController] InputManager instance not found!");
|
|
}
|
|
}
|
|
|
|
#region ITouchInputConsumer Implementation
|
|
|
|
public void OnTap(Vector2 tapPosition)
|
|
{
|
|
if (!_isWaitingForTap) return;
|
|
|
|
Debug.Log("[TapToStartController] First tap received! Starting game...");
|
|
|
|
// Stop waiting for tap
|
|
_isWaitingForTap = false;
|
|
|
|
// Stop blinking animation
|
|
if (_blinkTween != null)
|
|
{
|
|
_blinkTween.Stop();
|
|
_blinkTween = null;
|
|
}
|
|
|
|
// Hide finger UI
|
|
if (fingerContainer != null)
|
|
{
|
|
fingerContainer.SetActive(false);
|
|
}
|
|
|
|
// Unregister from input system
|
|
if (Input.InputManager.Instance != null)
|
|
{
|
|
Input.InputManager.Instance.SetDefaultConsumer(null);
|
|
Debug.Log("[TapToStartController] Unregistered from input");
|
|
}
|
|
|
|
// Tell game manager to start the game (it will handle the initial flap)
|
|
BirdPooperGameManager.Instance.BeginMinigame();
|
|
|
|
}
|
|
|
|
public void OnHoldStart(Vector2 position) { }
|
|
public void OnHoldMove(Vector2 position) { }
|
|
public void OnHoldEnd(Vector2 position) { }
|
|
|
|
#endregion
|
|
|
|
internal override void OnManagedDestroy()
|
|
{
|
|
// Stop blinking animation if active
|
|
if (_blinkTween != null)
|
|
{
|
|
_blinkTween.Stop();
|
|
_blinkTween = null;
|
|
}
|
|
|
|
// Unregister from input if still registered
|
|
if (_isWaitingForTap && Input.InputManager.Instance != null)
|
|
{
|
|
Input.InputManager.Instance.SetDefaultConsumer(null);
|
|
}
|
|
|
|
base.OnManagedDestroy();
|
|
}
|
|
}
|
|
}
|
|
|