Esempio n. 1
0
        private float GetMutedReplyPlayingTime(LocalizedReply lr)
        {
            float time = 0;

            for (int i = 0; i < lr.SubParts.Count; i++)
            {
                time += lr.SubParts[i].DelayBeforePlaying;
                time += 0.1f;
            }
            return(time);
        }
Esempio n. 2
0
        /// <summary>
        /// Starts saying the reply by this <see cref="DialogActor"/>,
        /// and returns the total length of the audio clips corresponding to the reply in the specified language if it isn't text only.
        /// If it is, returns 0.
        /// </summary>
        /// <param name="reply">The <see cref="Reply"/> to say.</param>
        /// <returns>Returns the length of the audio clip corresponding to the reply in the current language. Returns 0 if it is text only.</returns>
        public float SayReply(Reply reply, DialogPlayer associatedPlayer)
        {
            LocalizedReply currentLanguageReply = reply.GetReplyForLanguage(DialogEngineRuntime.Instance.DialogLanguage);

            if (currentLanguageReply == null)
            {
                throw new Exception("The language you are trying to use is not defined in the reply you are trying to say. Reply name: " + reply.name);
            }

            if (playReplyCoroutine != null)
            {
                StopCoroutine(playReplyCoroutine);
            }

            playReplyCoroutine = StartCoroutine(PlayReplyCoroutine(currentLanguageReply, associatedPlayer, reply.TextOnly));

            if (reply.TextOnly)
            {
                return(GetMutedReplyPlayingTime(currentLanguageReply));
            }
            return(currentLanguageReply.CompleteLength);
        }
Esempio n. 3
0
        /// <summary>
        /// The coroutine responsible of playing the reply: it plays all the reply parts, waits the user-specified time
        /// between each part etc.
        /// </summary>
        /// <param name="localizedReply">The reply in the current language.</param>
        /// <param name="associatedPlayer">The player of the reply.</param>
        /// <param name="textOnly">Is this reply text only?</param>
        private IEnumerator PlayReplyCoroutine(LocalizedReply localizedReply, DialogPlayer associatedPlayer, bool textOnly)
        {
            PlayingDialog = true;

            for (int i = 0; i < localizedReply.SubParts.Count; i++)
            {
                // Get the current reply
                ReplyPart currentPart = localizedReply.SubParts[i];

                // Set the current audio file
                if (!textOnly)
                {
                    audioSource.clip = currentPart.Audio;
                }

                // Wait the specified amount of time before saying the reply and then play it
                yield return(new WaitForSeconds(currentPart.DelayBeforePlaying));

                // Show the current subtitles
                if (associatedPlayer != null)
                {
                    associatedPlayer.CurrentReplySubtitles = currentPart.Subtitles; // Set the subtitles AFTER waiting for muted dialogs
                }
                if (!textOnly)
                {
                    audioSource.PlayOneShot(currentPart.Audio);
                    // Then wait for the end of this reply part
                    yield return(new WaitForSeconds(currentPart.Audio.length));

                    PlayingDialog = false;
                }
                else
                {
                    yield return(new WaitForSeconds(0.1f));

                    PlayingDialog = false;
                }
            }
        }
Esempio n. 4
0
        public float SayReply(Reply reply, DialogPlayer associatedPlayer, string forcedLanguage)
        {
            LocalizedReply currentLanguageReply = reply.GetReplyForLanguage(forcedLanguage);

            if (currentLanguageReply == null)
            {
                throw new Exception("The language you are trying to use is not defined in the reply you are trying to say.");
            }

            if (playReplyCoroutine != null)
            {
                StopCoroutine(playReplyCoroutine);
            }

            playReplyCoroutine = StartCoroutine(PlayReplyCoroutine(currentLanguageReply, associatedPlayer, reply.TextOnly));

            if (reply.TextOnly)
            {
                return(0);
            }
            return(currentLanguageReply.CompleteLength);
        }