Re: Don't Disable Response Menu and Global Delay
Posted: Sun Feb 09, 2020 4:10 pm
I think the example does work the way I want it to.
Support and discussion forum for Pixel Crushers products
https://www.pixelcrushers.com:443/phpbb/
https://www.pixelcrushers.com:443/phpbb/viewtopic.php?t=2911
Code: Select all
private const float DELAY = 0.55f;
private bool hasShownSubtitle;
private int lastSpeakerId;
private StandardUISubtitlePanel lastSubtitlePanel;
private StandardUIMenuPanel lastMenuPanel;
private Coroutine typeWriterDelay;
private float typeWriterSpeed;
public override void ShowSubtitle(Subtitle subtitle)
{
var panel = subtitle.speakerInfo.isNPC
? conversationUIElements.defaultNPCSubtitlePanel
: conversationUIElements.defaultPCSubtitlePanel;
var isSameSpeakerSamePanel = panel == lastSubtitlePanel && subtitle.speakerInfo.id == lastSpeakerId &&
lastMenuPanel == null;
if (hasShownSubtitle && !isSameSpeakerSamePanel)
{
typeWriterSpeed = panel.GetTypewriterSpeed();
panel.SetTypewriterSpeed(0);
typeWriterDelay = StartCoroutine(StartTypingAfterDelay(panel));
}
base.ShowSubtitle(subtitle);
hasShownSubtitle = true;
lastSpeakerId = subtitle.speakerInfo.id;
lastSubtitlePanel = panel;
lastMenuPanel = null;
}
private IEnumerator StartTypingAfterDelay(StandardUISubtitlePanel panel)
{
yield return new WaitForSeconds(DELAY);
panel.SetTypewriterSpeed(typeWriterSpeed);
panel.GetTypewriter().Start();
typeWriterDelay = null;
}
public override void HideSubtitle(Subtitle subtitle)
{
var nextLine = DialogueManager.currentConversationState.firstNPCResponse ??
DialogueManager.currentConversationState.pcAutoResponse;
var endOfConversation = !DialogueManager.currentConversationState.hasAnyResponses;
if (hasShownSubtitle &&
(nextLine == null || nextLine.destinationEntry.ActorID != lastSpeakerId || endOfConversation))
{
base.HideSubtitle(subtitle);
}
}
public override void ShowResponses(Subtitle subtitle, Response[] responses, float timeout)
{
base.ShowResponses(subtitle, responses, timeout);
if (lastSubtitlePanel)
{
lastSubtitlePanel.Close();
}
lastSpeakerId = -1;
lastSubtitlePanel = null;
lastMenuPanel = conversationUIElements.defaultMenuPanel;
}