Update to the timeline triggering logic

This commit is contained in:
Michal Pikulski
2025-10-06 16:16:41 +02:00
committed by Michal Pikulski
parent fd611ac27f
commit bdec77d36f
8 changed files with 875 additions and 933 deletions

View File

@@ -94,7 +94,7 @@ namespace Interactions
}
_currentMapping = mapping;
_currentTimelineIndex = 0;
// _currentTimelineIndex = 0;
return await PlayTimelineSequence(player, follower);
}
@@ -155,7 +155,7 @@ namespace Interactions
if (timelineAsset == null)
{
Debug.LogWarning("[InteractionTimelineAction] Timeline asset is null");
return true;
return true; // Return true to continue the interaction flow
}
// Set the timeline asset
@@ -205,14 +205,26 @@ namespace Interactions
// Create a task completion source to await the timeline completion
_currentPlaybackTCS = new TaskCompletionSource<bool>();
// Register for the stopped event if not already registered
playableDirector.stopped -= OnPlayableDirectorStopped;
playableDirector.stopped += OnPlayableDirectorStopped;
// Log the timeline playback
Debug.Log($"[InteractionTimelineAction] Playing timeline {timelineAsset.name} for event {mapping.eventType}");
// Play the timeline
playableDirector.Play();
// Start a timeout coroutine for safety using the mapping's timeout
StartCoroutine(TimeoutCoroutine(mapping.timeoutSeconds));
// Wait for the timeline to complete (or timeout)
// Await the timeline completion (will be signaled by the OnPlayableDirectorStopped callback)
bool result = await _currentPlaybackTCS.Task;
// Log completion
Debug.Log($"[InteractionTimelineAction] Timeline {timelineAsset.name} playback completed with result: {result}");
// Clear the task completion source
_currentPlaybackTCS = null;
return result;
@@ -220,10 +232,13 @@ namespace Interactions
private void OnPlayableDirectorStopped(PlayableDirector director)
{
if (director == playableDirector && _currentPlaybackTCS != null)
{
_currentPlaybackTCS.TrySetResult(true);
}
if (director != playableDirector || _currentPlaybackTCS == null)
return;
Debug.Log($"[InteractionTimelineAction] PlayableDirector stopped. Signaling completion.");
// Signal completion when the director stops
_currentPlaybackTCS.TrySetResult(true);
}
private System.Collections.IEnumerator TimeoutCoroutine(float timeoutDuration)