More dialogue improvements, barks stop on dialogue now

This commit is contained in:
2025-10-17 12:28:06 +02:00
parent 147c9c4312
commit 1e80a44f7a
7 changed files with 1589 additions and 779 deletions

View File

@@ -23,13 +23,15 @@ namespace Beyond
[Header("Events")]
[Tooltip("Actions to perform if the condition is true.")]
public UnityEvent onConditionTrue;
[Tooltip("Actions to perform if the condition is false.")]
public UnityEvent onConditionFalse;
// This field is used by the custom editor for the Lua wizard.
[HideInInspector]
public DialogueDatabase selectedDatabase = null;
[Tooltip("How often to check the condition (in seconds). If zero, only checks on start/load.")]
public float CheckInterval = 1.0f;
private bool hasFired = false;
@@ -40,6 +42,8 @@ namespace Beyond
{
base.Start();
CheckConditionAndExecute();
if (CheckInterval > 0)
InvokeRepeating("CheckConditionAndExecute", CheckInterval + (Random.value * CheckInterval), CheckInterval);
}
/// <summary>

View File

@@ -70,6 +70,9 @@ namespace Beyond // Ensure this namespace matches your project structure
public bool IsPlaying => m_audioSource != null && m_audioSource.isPlaying;
// --- NEW: Flag to control bark playback ---
private bool m_isPaused = false;
// --- Core Methods ---
public override void Awake()
@@ -93,6 +96,29 @@ namespace Beyond // Ensure this namespace matches your project structure
SetupAudioSource();
InitializeSaveData();
BuildConversationLookup();
}
// --- NEW: Subscribe to Dialogue System events ---
private void OnEnable()
{
var dialogueSystemEvents = DialogueManager.instance.GetComponent<DialogueSystemEvents>();
if (dialogueSystemEvents != null)
{
dialogueSystemEvents.conversationEvents.onConversationStart.AddListener(OnConversationStart);
dialogueSystemEvents.conversationEvents.onConversationEnd.AddListener(OnConversationEnd);
}
}
// --- NEW: Unsubscribe from Dialogue System events ---
private void OnDisable()
{
var dialogueSystemEvents = DialogueManager.instance.GetComponent<DialogueSystemEvents>();
if (dialogueSystemEvents != null)
{
dialogueSystemEvents.conversationEvents.onConversationStart.RemoveListener(OnConversationStart);
dialogueSystemEvents.conversationEvents.onConversationEnd.RemoveListener(OnConversationEnd);
}
}
private void SetupAudioSource()
@@ -152,6 +178,9 @@ namespace Beyond // Ensure this namespace matches your project structure
/// <returns>The AudioClip that will be played (or null if none/delayed).</returns>
public AudioClip PlayBark(int entryIndex, Transform barkTarget = null, int specificBarkIndex = -1)
{
// --- MODIFIED: Check if barks are paused ---
if (m_isPaused) return null;
if (entryIndex < 0 || entryIndex >= m_barks.Length)
{
Debug.LogError($"BarkManager: Invalid entryIndex {entryIndex}.", this);
@@ -223,6 +252,9 @@ namespace Beyond // Ensure this namespace matches your project structure
/// </summary>
public void PlayBark(string conversation, Transform barkTarget = null)
{
// --- MODIFIED: Check if barks are paused ---
if (m_isPaused) return;
if (m_conversationToEntry.TryGetValue(conversation, out int entryIndex))
{
// Determine target *before* queuing, store null if Player isn't available/needed
@@ -248,6 +280,9 @@ namespace Beyond // Ensure this namespace matches your project structure
/// </summary>
public void PlayBarkFromQueue(int entryIndex, Transform barkTarget = null)
{
// --- MODIFIED: Check if barks are paused ---
if (m_isPaused) return;
// Queue the original target (null if default intended). Update loop will resolve Player.Instance if needed.
m_barkQueue.Enqueue(new QueuedBarkRequest { entryIndex = entryIndex, target = barkTarget });
}
@@ -267,6 +302,9 @@ namespace Beyond // Ensure this namespace matches your project structure
/// </summary>
private AudioClip PlayBarkImmediately(BarkEntry barkEntry, Transform targetForText, int specificBarkIndex = -1)
{
// --- MODIFIED: Check if barks are paused ---
if (m_isPaused) return null;
if (barkEntry.barks == null || barkEntry.barks.Length == 0) return null;
Bark barkToPlay = null;
@@ -361,6 +399,9 @@ namespace Beyond // Ensure this namespace matches your project structure
private void Update()
{
// --- MODIFIED: Check if barks are paused ---
if (m_isPaused) return;
// Process the queue for externally triggered RANDOM barks
if (m_barkQueue.Count > 0 && !IsPlaying)
{
@@ -382,5 +423,45 @@ namespace Beyond // Ensure this namespace matches your project structure
PlayBark(request.entryIndex, targetForText, -1);
}
}
// --- NEW: Event handlers for conversation start and end ---
private void OnConversationStart(Transform actor)
{
//PauseBarks();
StopBarks();
}
private void OnConversationEnd(Transform actor)
{
//ResumeBarks();
}
// --- NEW: Public methods to pause and resume barks ---
public void StopBarks()
{
if (m_audioSource != null && m_audioSource.isPlaying)
{
m_audioSource.Stop();
}
m_barkQueue.Clear(); // Clear any pending barks
}
public void PauseBarks()
{
m_isPaused = true;
if (m_audioSource != null && m_audioSource.isPlaying)
{
m_audioSource.Pause();
}
m_barkQueue.Clear(); // Clear any pending barks
}
public void ResumeBarks()
{
m_isPaused = false;
if (m_audioSource != null)
{
m_audioSource.UnPause();
}
}
}
}