Working Dialogue

This commit is contained in:
Michal Pikulski
2025-09-28 11:56:13 +02:00
parent 665cfa89c6
commit 02031335e3
5 changed files with 158 additions and 24 deletions

View File

@@ -23,8 +23,11 @@ namespace Dialogue
[SerializeField] private AudioSource typingSoundSource;
[SerializeField] private float typingSoundFrequency = 3; // Play sound every X characters
[SerializeField] private bool useRichText = true; // Whether to respect rich text tags
[SerializeField] private float dialogueDisplayTime = 1.5f; // Time in seconds to display dialogue before showing prompt
[SerializeField] private string dialoguePromptText = ". . ."; // Text to show as a prompt for available dialogue
private Coroutine typewriterCoroutine;
private Coroutine promptUpdateCoroutine;
private string currentFullText = string.Empty;
private bool isVisible = false;
@@ -56,6 +59,13 @@ namespace Dialogue
StopCoroutine(typewriterCoroutine);
typewriterCoroutine = null;
}
// Stop any prompt update coroutine
if (promptUpdateCoroutine != null)
{
StopCoroutine(promptUpdateCoroutine);
promptUpdateCoroutine = null;
}
}
/// <summary>
@@ -105,6 +115,66 @@ namespace Dialogue
if (!isVisible)
Show();
}
/// <summary>
/// Display a dialogue line and handle prompt visibility afterward
/// </summary>
/// <param name="line">The dialogue line to display</param>
/// <param name="hasMoreDialogue">Whether there are more dialogue lines available</param>
public void DisplayDialogueLine(string line, bool hasMoreDialogue)
{
// Cancel any existing prompt update
if (promptUpdateCoroutine != null)
{
StopCoroutine(promptUpdateCoroutine);
promptUpdateCoroutine = null;
}
// Display the dialogue line
if (!string.IsNullOrEmpty(line))
{
SetText(line);
// After a delay, update the prompt visibility
promptUpdateCoroutine = StartCoroutine(UpdatePromptAfterDelay(hasMoreDialogue));
}
else
{
// If no line to display, update prompt visibility immediately
UpdatePromptVisibility(hasMoreDialogue);
}
}
/// <summary>
/// Update the speech bubble to either show a prompt or hide based on dialogue availability
/// </summary>
/// <param name="hasDialogueAvailable">Whether dialogue is available</param>
public void UpdatePromptVisibility(bool hasDialogueAvailable)
{
if (hasDialogueAvailable)
{
Show();
SetText(dialoguePromptText);
}
else
{
Hide();
}
}
/// <summary>
/// Coroutine to update the prompt visibility after a delay
/// </summary>
private IEnumerator UpdatePromptAfterDelay(bool hasMoreDialogue)
{
// Wait for the configured display time
yield return new WaitForSeconds(dialogueDisplayTime);
// Update the prompt visibility
UpdatePromptVisibility(hasMoreDialogue);
promptUpdateCoroutine = null;
}
/// <summary>
/// Change the display mode