Re: How to Continue Conversations
Posted: Sun Apr 07, 2019 4:22 pm
I use master audio, there is a way to display the continue button when the audio has finished playing?
Support and discussion forum for Pixel Crushers products
https://www.pixelcrushers.com:443/phpbb/
https://www.pixelcrushers.com:443/phpbb/viewtopic.php?t=1728
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
using DarkTonic.MasterAudio;
using System.Collections;
public class HideContinueButtonUntilSongEnds : MonoBehaviour, ICustomEventReceiver
{
private bool songEnded;
// Dialogue System calls this method just before showing a subtitle:
void OnConversationLine(Subtitle subtitle)
{
StartCoroutine(MonitorSong(subtitle)); // Start coroutine to handle continue button.
}
IEnumerator MonitorSong(Subtitle subtitle)
{
songEnded = false;
var ui = DialogueManager.dialogueUI as AbstractDialogueUI;
yield return new WaitForEndOfFrame(); // Let dialogue UI set up subtitle.
ui.HideContinueButton(subtitle); // Hide continue button until song ends.
while (!songEnded) { yield return null; } // Wait for song to end.
ui.ShowContinueButton(subtitle); // Song ended, so show continue button.
}
// Methods to satisfy ICustomEventReceiver:
void OnEnable() { RegisterReceiver(); }
void OnDisable() { if (MasterAudio.SafeInstance == null || MasterAudio.AppIsShuttingDown) return; else UnregisterReceiver(); }
public void ReceiveEvent(string customEventName, Vector3 originPoint) {
if (customEventName == "SongEnded") songEnded = true;
}
public bool SubscribesToEvent(string customEventName) {
return string.IsNullOrEmpty(customEventName)) ? false : _eventsSubscribedTo.Contains(customEventName);
}
public void RegisterReceiver() {
MasterAudio.AddCustomEventReceiver(this, transform);
}
public void UnregisterReceiver() {
MasterAudio.RemoveCustomEventReceiver(this);
}
public IList<AudioEventGroup> GetAllEvents() {
var events = new List<AudioEventGroup>();
for (var i = 0; i < _eventsSubscribedTo.Count; i++) {
events.Add(new AudioEventGroup {
customEventName = _eventsSubscribedTo[i]
});
}
return events;
}
}
Code: Select all
SetContinueMode(false);
MAPlaylistClip(entrytag);
required SetContinueMode(true)@Message(SongEnded);
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
using DarkTonic.MasterAudio;
using System.Collections;
public class SequencerMessageWhenSongEnds : MonoBehaviour, ICustomEventReceiver
{
void OnEnable() { RegisterReceiver(); }
void OnDisable() { if (MasterAudio.SafeInstance == null || MasterAudio.AppIsShuttingDown) return; else UnregisterReceiver(); }
public void ReceiveEvent(string customEventName, Vector3 originPoint) {
if (customEventName == "SongEnded") Sequencer.Message("SongEnded");
}
public bool SubscribesToEvent(string customEventName) {
return string.IsNullOrEmpty(customEventName)) ? false : _eventsSubscribedTo.Contains(customEventName);
}
public void RegisterReceiver() {
MasterAudio.AddCustomEventReceiver(this, transform);
}
public void UnregisterReceiver() {
MasterAudio.RemoveCustomEventReceiver(this);
}
public IList<AudioEventGroup> GetAllEvents() {
var events = new List<AudioEventGroup>();
for (var i = 0; i < _eventsSubscribedTo.Count; i++) {
events.Add(new AudioEventGroup {
customEventName = _eventsSubscribedTo[i]
});
}
return events;
}
}
Code: Select all
SetContinueMode(false);
WaitForMessage(SeparateWindowClosed)
Code: Select all
Sequencer.Message("SeparateWindowClosed");