Short Subtitles as Barks disabling text too soon
Posted: Fri Apr 24, 2015 4:24 pm
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();
}
}
}
}
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();
}
}
}
}