Check if any bark is happening in code

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Haytam95
Posts: 23
Joined: Sun Mar 15, 2020 5:56 pm

Check if any bark is happening in code

Post by Haytam95 »

Hi!

I'm trying to make a dynamic UI that hides or show if the character is speaking. This is to prevent UI overlaping .

I have the following code:

Code: Select all

private void ManagePopupVisibility()
        {
            var shouldShow = true;
        
            if(pawnSearching == null) shouldShow = false; // if there is no pawn hiding, don't show the popup
            if(DialogueManager.instance != null && DialogueManager.isConversationActive) shouldShow = false; // if there is a conversation, don't show the popup (to prevent overlaping)
            if(_popup.IsShowing && _popup.IsVisible) shouldShow = false; // if the popup is already showing, don't show it again
        
        
            if(shouldShow)
            {
                _popup.Show();
            }
            else
            {
                _popup.Hide();
            }
        }
That works pretty well. I would like to use something like

Code: Select all

DialogueManager.isConversationActive
, but for Barks.
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Check if any bark is happening in code

Post by Tony Li »

Hi,

There's no DialogueManager.isBarkActive, but you add a script with OnBarkStart/End methods to the Dialogue Manager. Something like:

Code: Select all

public class BarkWatcher : MonoBehaviour
{
    private List<Transform> activeBarkers = new List<Transform>();
    
    public bool IsBarkActive() { return activeBarkers.Count > 0; }
    
    void OnBarkStart(Transform barker) { activeBarkers.Add(barker); }
    
    void OnBarkEnd(Transform barker) { activeBarkers.Remove(barker); }    
}
You may also be interested in bark groups. DemoScene2's enemies demonstrate a bark group.
User avatar
Haytam95
Posts: 23
Joined: Sun Mar 15, 2020 5:56 pm

Re: Check if any bark is happening in code

Post by Haytam95 »

This worked great Tony, thank you! Here is the result (keep and eye on the "Hold [] to stop searching") :)

Image

The only thing I needed to add to my script that controls the popup was:

Code: Select all


void OnStart() {
   _barkWatcher = DialogueManager.instance.transform.GetComponent<BarkWatcher>();
}

/// On another function

if(_barkWatcher.IsBarkActive()) shouldShow = false;

User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Check if any bark is happening in code

Post by Tony Li »

Looks great!
Post Reply