Short Subtitles as Barks disabling text too soon

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 22118
Joined: Thu Jul 18, 2013 1:27 pm

Short Subtitles as Barks disabling text too soon

Post by Tony Li »

For the benefit of other readers, we ended up using a custom dialogue UI that uses the participants' bark UIs. It hides all active barks when a conversation begins, and ensures that only one participant's bark is active at a time. Here's the basic code:

using UnityEngine;

using UnityEngine.UI;



namespace PixelCrushers.DialogueSystem

{



/// <summary>

/// This is a variation of UnityUIDialogueUI that uses the speaker's bark UI for subtitles.

/// </summary>

public class UnityUIBarkSubtitleDialogueUICustom : UnityUIDialogueUI

{



private UnityUIBarkUI lastBarkUI = null;



public override void Open()

{

HideAllBarks();

base.Open();

}



public override void Close()

{

HideBarkUI(lastBarkUI);

base.Close();

}



public override void ShowSubtitle(Subtitle subtitle)

{





var barkUI = subtitle.speakerInfo.transform.GetComponentInChildren<UnityUIBarkUI>();

if (barkUI != lastBarkUI) HideBarkUI(lastBarkUI);

lastBarkUI = barkUI;

barkUI.Bark(subtitle);

HideResponses();

}



private void HideBarkUI(UnityUIBarkUI barkUI)

{

if (barkUI != null)

{

barkUI.OnBarkEnd();

}

}



private void HideAllBarks()

{

foreach (var barkUI in FindObjectsOfType<UnityUIBarkUI>())

{

if (barkUI.IsPlaying) barkUI.OnBarkEnd();

}

}



}



}
Post Reply