128 lines
3.7 KiB
C#
128 lines
3.7 KiB
C#
using Input;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Cinematics
|
|
{
|
|
public class SkipCinematic : MonoBehaviour, ITouchInputConsumer
|
|
{
|
|
[Header("Configuration")]
|
|
[SerializeField] private float holdDuration = 2.0f;
|
|
[SerializeField] private Image radialProgressBar;
|
|
|
|
private float _holdStartTime;
|
|
private bool _isHolding;
|
|
private bool _skipPerformed;
|
|
|
|
void Start()
|
|
{
|
|
// Reset the progress bar
|
|
if (radialProgressBar != null)
|
|
{
|
|
radialProgressBar.fillAmount = 0f;
|
|
}
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
if (CinematicsManager.Instance.IsCinematicPlaying)
|
|
HandleCinematicStarted();
|
|
|
|
CinematicsManager.Instance.OnCinematicStarted += HandleCinematicStarted;
|
|
CinematicsManager.Instance.OnCinematicStopped += HandleCinematicStopped;
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
CinematicsManager.Instance.OnCinematicStarted -= HandleCinematicStarted;
|
|
CinematicsManager.Instance.OnCinematicStopped -= HandleCinematicStopped;
|
|
// If still registered, unregister input override
|
|
InputManager.Instance.UnregisterOverrideConsumer(this);
|
|
}
|
|
|
|
private void HandleCinematicStarted()
|
|
{
|
|
InputManager.Instance.RegisterOverrideConsumer(this);
|
|
}
|
|
|
|
private void HandleCinematicStopped()
|
|
{
|
|
InputManager.Instance.UnregisterOverrideConsumer(this);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
// Only process while cinematic is playing and we're holding
|
|
if (_isHolding && CinematicsManager.Instance.IsCinematicPlaying)
|
|
{
|
|
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();
|
|
Debug.Log("Cinematic skipped via touch hold");
|
|
|
|
// 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;
|
|
|
|
Debug.Log("Starting cinematic skip gesture");
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
Debug.Log("Cinematic skip gesture canceled");
|
|
}
|
|
#endregion
|
|
}
|
|
}
|