Update to the timeline triggering logic
This commit is contained in:
committed by
Michal Pikulski
parent
fd611ac27f
commit
bdec77d36f
@@ -314,7 +314,8 @@ namespace Interactions
|
||||
}
|
||||
}
|
||||
|
||||
_followerController.GoToPointAndReturn(targetPosition, _playerRef.transform);
|
||||
// Use the new GoToPoint method instead of GoToPointAndReturn
|
||||
_followerController.GoToPoint(targetPosition);
|
||||
|
||||
// Await follower arrival
|
||||
await tcs.Task;
|
||||
@@ -356,7 +357,8 @@ namespace Interactions
|
||||
}
|
||||
}
|
||||
|
||||
_followerController.GoToPointAndReturn(targetPosition, _playerRef.transform);
|
||||
// Use the new GoToPoint method instead of GoToPointAndReturn
|
||||
_followerController.GoToPoint(targetPosition);
|
||||
|
||||
// Await follower arrival
|
||||
await tcs.Task;
|
||||
@@ -368,10 +370,32 @@ namespace Interactions
|
||||
if (!_interactionInProgress)
|
||||
return;
|
||||
|
||||
// Dispatch FollowerArrived event
|
||||
// Dispatch InteractingCharacterArrived event and WAIT for all actions to complete
|
||||
// This ensures we wait for any timeline animations to finish before proceeding
|
||||
Debug.Log("[Interactable] Follower arrived, dispatching InteractingCharacterArrived event and waiting for completion");
|
||||
await DispatchEventAsync(InteractionEventType.InteractingCharacterArrived);
|
||||
Debug.Log("[Interactable] All InteractingCharacterArrived actions completed, proceeding with interaction");
|
||||
|
||||
// After all FollowerArrived actions complete, proceed to character arrived
|
||||
// Check if we have any components that might have paused the interaction flow
|
||||
bool hasTimelineActions = false;
|
||||
foreach (var action in _registeredActions)
|
||||
{
|
||||
if (action is InteractionTimelineAction timelineAction &&
|
||||
timelineAction.respondToEvents.Contains(InteractionEventType.InteractingCharacterArrived) &&
|
||||
timelineAction.pauseInteractionFlow)
|
||||
{
|
||||
hasTimelineActions = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Tell the follower to return to the player
|
||||
if (_followerController != null && _playerRef != null)
|
||||
{
|
||||
_followerController.ReturnToPlayer(_playerRef.transform);
|
||||
}
|
||||
|
||||
// After all InteractingCharacterArrived actions complete, proceed to character arrived
|
||||
await BroadcastCharacterArrivedAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user