2025-10-14 15:53:58 +02:00
|
|
|
using Core;
|
2025-11-04 11:11:27 +01:00
|
|
|
using Core.Lifecycle;
|
2025-10-13 09:22:18 +02:00
|
|
|
using Input;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace Cinematics
|
|
|
|
|
{
|
2025-11-04 11:11:27 +01:00
|
|
|
public class SkipCinematic : ManagedBehaviour, ITouchInputConsumer
|
2025-10-13 09:22:18 +02:00
|
|
|
{
|
|
|
|
|
[Header("Configuration")]
|
|
|
|
|
[SerializeField] private float holdDuration = 2.0f;
|
|
|
|
|
[SerializeField] private Image radialProgressBar;
|
|
|
|
|
|
|
|
|
|
private float _holdStartTime;
|
|
|
|
|
private bool _isHolding;
|
|
|
|
|
private bool _skipPerformed;
|
2025-10-16 19:43:19 +02:00
|
|
|
private bool _initialized = false;
|
2025-10-13 09:22:18 +02:00
|
|
|
|
2025-11-04 11:11:27 +01:00
|
|
|
public override int ManagedAwakePriority => 180; // Cinematic UI
|
2025-10-16 19:43:19 +02:00
|
|
|
|
2025-11-04 11:11:27 +01:00
|
|
|
protected override void OnManagedAwake()
|
2025-10-13 09:22:18 +02:00
|
|
|
{
|
|
|
|
|
// Reset the progress bar
|
|
|
|
|
if (radialProgressBar != null)
|
|
|
|
|
{
|
|
|
|
|
radialProgressBar.fillAmount = 0f;
|
|
|
|
|
}
|
2025-10-16 19:43:19 +02:00
|
|
|
|
|
|
|
|
// Subscribe to CinematicsManager events now that boot is complete
|
|
|
|
|
SubscribeToCinematicsEvents();
|
|
|
|
|
|
2025-11-04 11:11:27 +01:00
|
|
|
Logging.Debug("[SkipCinematic] Initialized");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
base.OnDestroy();
|
|
|
|
|
|
|
|
|
|
// Clean up subscriptions
|
|
|
|
|
UnsubscribeFromCinematicsEvents();
|
2025-10-16 19:43:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SubscribeToCinematicsEvents()
|
|
|
|
|
{
|
|
|
|
|
if (CinematicsManager.Instance == null) return;
|
|
|
|
|
|
|
|
|
|
// First unsubscribe to prevent duplicate subscriptions
|
|
|
|
|
UnsubscribeFromCinematicsEvents();
|
2025-10-13 14:25:11 +02:00
|
|
|
|
2025-10-16 19:43:19 +02:00
|
|
|
// Now subscribe
|
2025-10-13 12:41:04 +02:00
|
|
|
CinematicsManager.Instance.OnCinematicStarted += HandleCinematicStarted;
|
|
|
|
|
CinematicsManager.Instance.OnCinematicStopped += HandleCinematicStopped;
|
2025-10-16 19:43:19 +02:00
|
|
|
|
|
|
|
|
// Check if a cinematic is already playing
|
|
|
|
|
if (CinematicsManager.Instance.IsCinematicPlaying)
|
|
|
|
|
HandleCinematicStarted();
|
|
|
|
|
|
|
|
|
|
Logging.Debug("[SkipCinematic] Subscribed to cinematics events");
|
2025-10-13 09:22:18 +02:00
|
|
|
}
|
2025-10-16 19:43:19 +02:00
|
|
|
|
|
|
|
|
private void UnsubscribeFromCinematicsEvents()
|
2025-10-13 09:22:18 +02:00
|
|
|
{
|
2025-10-16 19:43:19 +02:00
|
|
|
if (CinematicsManager.Instance != null)
|
|
|
|
|
{
|
|
|
|
|
CinematicsManager.Instance.OnCinematicStarted -= HandleCinematicStarted;
|
|
|
|
|
CinematicsManager.Instance.OnCinematicStopped -= HandleCinematicStopped;
|
|
|
|
|
Logging.Debug("[SkipCinematic] Unsubscribed from cinematics events");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If still registered as an input override consumer, unregister
|
|
|
|
|
if (InputManager.Instance != null)
|
|
|
|
|
{
|
|
|
|
|
InputManager.Instance.UnregisterOverrideConsumer(this);
|
|
|
|
|
Logging.Debug("[SkipCinematic] Unregistered as input override consumer");
|
|
|
|
|
}
|
2025-10-13 12:41:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleCinematicStarted()
|
|
|
|
|
{
|
2025-10-16 19:43:19 +02:00
|
|
|
if (InputManager.Instance != null)
|
|
|
|
|
{
|
|
|
|
|
InputManager.Instance.RegisterOverrideConsumer(this);
|
|
|
|
|
}
|
2025-10-13 12:41:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleCinematicStopped()
|
|
|
|
|
{
|
2025-10-16 19:43:19 +02:00
|
|
|
if (InputManager.Instance != null)
|
|
|
|
|
{
|
|
|
|
|
InputManager.Instance.UnregisterOverrideConsumer(this);
|
|
|
|
|
}
|
2025-10-13 09:22:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
// Only process while cinematic is playing and we're holding
|
2025-10-13 14:25:11 +02:00
|
|
|
if (_isHolding && CinematicsManager.Instance.IsCinematicPlaying)
|
2025-10-13 09:22:18 +02:00
|
|
|
{
|
|
|
|
|
float holdTime = Time.time - _holdStartTime;
|
|
|
|
|
float progress = Mathf.Clamp01(holdTime / holdDuration);
|
|
|
|
|
|
|
|
|
|
// Update progress bar
|
|
|
|
|
if (radialProgressBar != null)
|
|
|
|
|
{
|
|
|
|
|
radialProgressBar.fillAmount = progress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if we've held long enough to skip
|
|
|
|
|
if (progress >= 1.0f && !_skipPerformed)
|
|
|
|
|
{
|
|
|
|
|
_skipPerformed = true;
|
|
|
|
|
DoSkipCinematic();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DoSkipCinematic()
|
|
|
|
|
{
|
|
|
|
|
CinematicsManager.Instance.SkipCurrentCinematic();
|
2025-10-14 15:53:58 +02:00
|
|
|
Logging.Debug("Cinematic skipped via touch hold");
|
2025-10-13 09:22:18 +02:00
|
|
|
|
|
|
|
|
// Reset UI
|
|
|
|
|
if (radialProgressBar != null)
|
|
|
|
|
{
|
|
|
|
|
radialProgressBar.fillAmount = 0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remember to clear up input override
|
|
|
|
|
InputManager.Instance.UnregisterOverrideConsumer(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region ITouchInputConsumer Implementation
|
|
|
|
|
public void OnTap(Vector2 position)
|
|
|
|
|
{
|
|
|
|
|
// Not using tap for skipping
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnHoldStart(Vector2 position)
|
|
|
|
|
{
|
|
|
|
|
// Start tracking hold time
|
|
|
|
|
_isHolding = true;
|
|
|
|
|
_skipPerformed = false;
|
|
|
|
|
_holdStartTime = Time.time;
|
|
|
|
|
|
2025-10-14 15:53:58 +02:00
|
|
|
Logging.Debug("Starting cinematic skip gesture");
|
2025-10-13 09:22:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnHoldMove(Vector2 position)
|
|
|
|
|
{
|
|
|
|
|
// Hold movement is tracked in Update method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnHoldEnd(Vector2 position)
|
|
|
|
|
{
|
|
|
|
|
// Reset state when hold ends
|
|
|
|
|
_isHolding = false;
|
|
|
|
|
|
|
|
|
|
// Reset UI
|
|
|
|
|
if (radialProgressBar != null)
|
|
|
|
|
{
|
|
|
|
|
radialProgressBar.fillAmount = 0f;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-14 15:53:58 +02:00
|
|
|
Logging.Debug("Cinematic skip gesture canceled");
|
2025-10-13 09:22:18 +02:00
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|