Add skip functionality to Cinematics Manager
This commit is contained in:
112
Assets/Scripts/Cinematics/SkipCinematic.cs
Normal file
112
Assets/Scripts/Cinematics/SkipCinematic.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
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()
|
||||
{
|
||||
// Register as override consumer when enabled
|
||||
InputManager.Instance.RegisterOverrideConsumer(this);
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
// Unregister when disabled
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user