protected virtual WriterAudio GetWriterAudio() { if (writerAudio != null) { return(writerAudio); } writerAudio = GetComponent <WriterAudio>(); if (writerAudio == null) { writerAudio = gameObject.AddComponent <WriterAudio>(); } return(writerAudio); }
/// <summary> /// Write a line of story text to the Say Dialog. Must be started as a coroutine. /// </summary> /// <param name="text">The text to display.</param> /// <param name="clearPrevious">Clear any previous text in the Say Dialog.</param> /// <param name="waitForInput">Wait for player input before continuing once text is written.</param> /// <param name="fadeWhenDone">Fade out the Say Dialog when writing and player input has finished.</param> /// <param name="stopVoiceover">Stop any existing voiceover audio before writing starts.</param> /// <param name="voiceOverClip">Voice over audio clip to play.</param> /// <param name="onComplete">Callback to execute when writing and player input have finished.</param> public virtual IEnumerator DoSay(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, bool waitForVO, AudioClip voiceOverClip, Action onComplete) { var writer = GetWriter(); if (writer.IsWriting || writer.IsWaitingForInput) { writer.Stop(); while (writer.IsWriting || writer.IsWaitingForInput) { yield return(null); } } if (closeOtherDialogs) { for (int i = 0; i < activeSayDialogs.Count; i++) { var sd = activeSayDialogs[i]; if (sd.gameObject != gameObject) { sd.SetActive(false); } } } gameObject.SetActive(true); this.fadeWhenDone = fadeWhenDone; // Voice over clip takes precedence over a character sound effect if provided AudioClip soundEffectClip = null; if (voiceOverClip != null) { WriterAudio writerAudio = GetWriterAudio(); writerAudio.OnVoiceover(voiceOverClip); } else if (speakingCharacter != null) { soundEffectClip = speakingCharacter.SoundEffect; } writer.AttachedWriterAudio = writerAudio; yield return(StartCoroutine(writer.Write(text, clearPrevious, waitForInput, stopVoiceover, waitForVO, soundEffectClip, onComplete))); }