Page 1 of 1

Check if any bark is happening in code

Posted: Tue Oct 18, 2022 9:29 pm
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.

Re: Check if any bark is happening in code

Posted: Tue Oct 18, 2022 9:57 pm
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.

Re: Check if any bark is happening in code

Posted: Tue Oct 18, 2022 11:40 pm
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;


Re: Check if any bark is happening in code

Posted: Wed Oct 19, 2022 8:48 am
by Tony Li
Looks great!