Ejemplo n.º 1
0
        /**
         * <summary>The default Constructor.</summary>
         * <param name = "_speaker">The speaking character. If null, the line is considered a narration</param>
         * <param name = "_message">The subtitle text to display</param>
         * <param name = "lineID">The unique ID number of the line, as generated by the Speech Manager</param>
         * <param name = "_language">The currently-selected language</param>
         * <param name = "_isBackground">True if the line should play in the background, and not interrupt Actions or gameplay</param>
         * <param name = "_noAnimation">True if the speaking character should not play a talking animation</param>
         * <param name = "_runActionListInBackground">True if the ActionList that contains the call is set to Run In Background</param>
         */
        public Speech(Char _speaker, string _message, int lineID, string _language, bool _isBackground, bool _noAnimation, bool _runActionListInBackground = false)
        {
            // Clear rich text
            boldTagIndex = italicTagIndex = sizeTagIndex = colorTagIndex = -1;
            closingTags  = "";

            log.Clear();
            isBackground = _isBackground;
            runActionListInBackground = _runActionListInBackground;

            if (_speaker)
            {
                speaker           = _speaker;
                speaker.isTalking = !_noAnimation;
                log.speakerName   = _speaker.name;

                if (_speaker.GetComponent <Player>())
                {
                    if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow || !KickStarter.speechManager.usePlayerRealName)
                    {
                        log.speakerName = "Player";
                    }
                }

                if (_speaker.GetComponent <Hotspot>())
                {
                    if (_speaker.GetComponent <Hotspot>().hotspotName != "")
                    {
                        log.speakerName = _speaker.GetComponent <Hotspot>().hotspotName;
                    }
                }

                _speaker.ClearExpression();

                if (!_noAnimation)
                {
                    if (KickStarter.speechManager.lipSyncMode == LipSyncMode.Off)
                    {
                        speaker.isLipSyncing = false;
                    }
                    else if (KickStarter.speechManager.lipSyncMode == LipSyncMode.Salsa2D || KickStarter.speechManager.lipSyncMode == LipSyncMode.FromSpeechText || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadPamelaFile || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadSapiFile || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadPapagayoFile)
                    {
                        speaker.StartLipSync(KickStarter.dialog.GenerateLipSyncShapes(KickStarter.speechManager.lipSyncMode, lineID, speaker.name, _language, _message));
                    }
                    else if (KickStarter.speechManager.lipSyncMode == LipSyncMode.RogoLipSync)
                    {
                        RogoLipSyncIntegration.Play(_speaker, speaker.name, lineID, _language);
                    }
                }
            }
            else
            {
                if (speaker)
                {
                    speaker.isTalking = false;
                }
                speaker         = null;
                log.speakerName = "Narrator";
            }

            _message = DetermineGaps(_message);
            if (speechGaps.Count > 0)
            {
                gapIndex = 0;

                /*foreach (SpeechGap gap in speechGaps)
                 * {
                 *      if (gap.expressionID < 0)
                 *      {
                 *              displayDuration += (float) gap.waitTime;
                 *      }
                 * }*/
            }
            else
            {
                gapIndex = -1;
            }

            if (lineID > -1)
            {
                log.lineID = lineID;
            }

            // Play sound and time displayDuration to it
            if (lineID > -1 && log.speakerName != "" && KickStarter.speechManager.searchAudioFiles)
            {
                AudioClip clipObj = null;

                if (KickStarter.speechManager.autoNameSpeechFiles)
                {
                    string fullFilename = "Speech/";
                    string filename     = KickStarter.speechManager.GetLineFilename(lineID);
                    if (_language != "" && KickStarter.speechManager.translateAudio)
                    {
                        // Not in original language
                        fullFilename += _language + "/";
                    }
                    if (KickStarter.speechManager.placeAudioInSubfolders)
                    {
                        fullFilename += filename + "/";
                    }
                    fullFilename += filename + lineID;

                    clipObj = Resources.Load(fullFilename) as AudioClip;

                    if (clipObj == null && KickStarter.speechManager.fallbackAudio && Options.GetLanguage() > 0)
                    {
                        fullFilename = "Speech/";
                        if (KickStarter.speechManager.placeAudioInSubfolders)
                        {
                            fullFilename += filename + "/";
                        }
                        fullFilename += filename + lineID;
                        clipObj       = Resources.Load(fullFilename) as AudioClip;
                    }

                    if (clipObj == null)
                    {
                        ACDebug.Log("Cannot find audio file: " + fullFilename);
                    }
                }
                else
                {
                    clipObj = KickStarter.speechManager.GetLineCustomAudioClip(lineID, Options.GetLanguage());

                    if (clipObj == null && KickStarter.speechManager.fallbackAudio && Options.GetLanguage() > 0)
                    {
                        clipObj = KickStarter.speechManager.GetLineCustomAudioClip(lineID, 0);
                    }
                }

                if (clipObj)
                {
                    AudioSource audioSource = null;

                    if (_speaker != null)
                    {
                        if (!_noAnimation)
                        {
                            if (KickStarter.speechManager.lipSyncMode == LipSyncMode.FaceFX)
                            {
                                FaceFXIntegration.Play(speaker, log.speakerName + lineID, clipObj);
                            }
                        }

                        if (_speaker.speechAudioSource)
                        {
                            audioSource = _speaker.speechAudioSource;

                            if (_speaker.speechAudioSource.GetComponent <Sound>())
                            {
                                _speaker.speechAudioSource.GetComponent <Sound>().SetVolume(Options.optionsData.speechVolume);
                            }
                            else
                            {
                                _speaker.speechAudioSource.volume = Options.optionsData.speechVolume;
                            }
                        }
                        else
                        {
                            ACDebug.LogWarning(_speaker.name + " has no audio source component!");
                        }
                    }
                    else if (KickStarter.player && KickStarter.player.speechAudioSource)
                    {
                        KickStarter.player.speechAudioSource.volume = Options.optionsData.speechVolume;
                        audioSource = KickStarter.player.speechAudioSource;
                    }
                    else
                    {
                        audioSource = KickStarter.dialog.GetDefaultAudioSource();
                    }

                    if (audioSource != null)
                    {
                        audioSource.clip = clipObj;
                        audioSource.loop = false;
                        audioSource.Play();
                        hasAudio = true;
                    }

                    displayDuration = clipObj.length;
                }
                else
                {
                    displayDuration += KickStarter.speechManager.screenTimeFactor * GetLengthWithoutRichText(_message);
                    displayDuration  = Mathf.Max(displayDuration, KickStarter.speechManager.minimumDisplayTime);
                }
            }
            else
            {
                displayDuration += KickStarter.speechManager.screenTimeFactor * GetLengthWithoutRichText(_message);
                displayDuration  = Mathf.Max(displayDuration, KickStarter.speechManager.minimumDisplayTime);
            }

            log.fullText = _message;
            KickStarter.eventManager.Call_OnStartSpeech(_speaker, log.fullText, lineID);

            if (!CanScroll())
            {
                if (continueIndex > 0)
                {
                    continueTime = (continueIndex / KickStarter.speechManager.textScrollSpeed);
                }

                if (speechGaps.Count > 0)
                {
                    displayText = log.fullText.Substring(0, speechGaps[0].characterIndex);
                }
                else
                {
                    displayText = log.fullText;
                }
            }
            else
            {
                displayText = "";
                KickStarter.eventManager.Call_OnStartSpeechScroll(_speaker, log.fullText, lineID);
            }

            isAlive     = true;
            isSkippable = true;
            pauseGap    = false;
            endTime     = displayDuration;
            minSkipTime = KickStarter.speechManager.skipThresholdTime;
        }
Ejemplo n.º 2
0
        public Speech(Char _speaker, string _message, int lineID, string _language, bool _isBackground, bool _noAnimation)
        {
            log.Clear();
            isBackground = _isBackground;

            if (_speaker)
            {
                speaker           = _speaker;
                speaker.isTalking = !_noAnimation;
                log.speakerName   = _speaker.name;

                if (_speaker.GetComponent <Player>())
                {
                    if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow || !KickStarter.speechManager.usePlayerRealName)
                    {
                        log.speakerName = "Player";
                    }
                }

                if (_speaker.GetComponent <Hotspot>())
                {
                    if (_speaker.GetComponent <Hotspot>().hotspotName != "")
                    {
                        log.speakerName = _speaker.GetComponent <Hotspot>().hotspotName;
                    }
                }

                if (_speaker.portraitIcon != null)
                {
                    _speaker.portraitIcon.Reset();
                }

                if (!_noAnimation)
                {
                    if (KickStarter.speechManager.lipSyncMode == LipSyncMode.Off)
                    {
                        speaker.isLipSyncing = false;
                    }
                    else if (KickStarter.speechManager.lipSyncMode == LipSyncMode.Salsa2D || KickStarter.speechManager.lipSyncMode == LipSyncMode.FromSpeechText || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadPamelaFile || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadSapiFile || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadPapagayoFile)
                    {
                        speaker.StartLipSync(KickStarter.dialog.GenerateLipSyncShapes(KickStarter.speechManager.lipSyncMode, lineID, log.speakerName, _language, _message));
                    }
                }
            }
            else
            {
                if (speaker)
                {
                    speaker.isTalking = false;
                }
                speaker         = null;
                log.speakerName = "Narrator";
            }

            _message = AdvGame.ConvertTokens(_message);

            if (lineID > -1)
            {
                log.lineID = lineID;
            }

            // Play sound and time displayDuration to it
            if (lineID > -1 && log.speakerName != "" && KickStarter.speechManager.searchAudioFiles)
            {
                string fullFilename = "Speech/";
                string filename     = KickStarter.speechManager.GetLineFilename(lineID);
                if (_language != "" && KickStarter.speechManager.translateAudio)
                {
                    // Not in original language
                    fullFilename += _language + "/";
                }
                if (KickStarter.speechManager.placeAudioInSubfolders)
                {
                    fullFilename += filename + "/";
                }
                fullFilename += filename + lineID;

                AudioClip clipObj = Resources.Load(fullFilename) as AudioClip;
                if (clipObj)
                {
                    AudioSource audioSource = null;

                    if (_speaker != null)
                    {
                        if (!_noAnimation)
                        {
                            if (KickStarter.speechManager.lipSyncMode == LipSyncMode.FaceFX)
                            {
                                FaceFXIntegration.Play(speaker, log.speakerName + lineID, clipObj);
                            }
                        }

                        if (_speaker.GetComponent <AudioSource>())
                        {
                            _speaker.GetComponent <AudioSource>().volume = KickStarter.options.optionsData.speechVolume;
                            audioSource = _speaker.GetComponent <AudioSource>();
                        }
                        else
                        {
                            Debug.LogWarning(_speaker.name + " has no audio source component!");
                        }
                    }
                    else if (KickStarter.player && KickStarter.player.GetComponent <AudioSource>())
                    {
                        KickStarter.player.GetComponent <AudioSource>().volume = KickStarter.options.optionsData.speechVolume;
                        audioSource = KickStarter.player.GetComponent <AudioSource>();
                    }
                    else
                    {
                        audioSource = KickStarter.dialog.GetDefaultAudioSource();
                    }

                    if (audioSource != null)
                    {
                        audioSource.clip = clipObj;
                        audioSource.loop = false;
                        audioSource.Play();
                        hasAudio = true;
                    }

                    displayDuration = clipObj.length;
                }
                else
                {
                    displayDuration = KickStarter.speechManager.screenTimeFactor * (float)_message.Length;
                    if (displayDuration < 0.5f)
                    {
                        displayDuration = 0.5f;
                    }

                    Debug.Log("Cannot find audio file: " + fullFilename);
                }
            }
            else
            {
                displayDuration = KickStarter.speechManager.screenTimeFactor * (float)_message.Length;
                if (displayDuration < 0.5f)
                {
                    displayDuration = 0.5f;
                }
            }

            _message = DetermineGaps(_message);

            if (speechGaps.Count > 0)
            {
                gapIndex = 0;
                foreach (SpeechGap gap in speechGaps)
                {
                    displayDuration += (float)gap.waitTime;
                }
            }
            else
            {
                gapIndex = -1;
            }

            log.fullText = _message;

            if (!KickStarter.speechManager.scrollSubtitles)
            {
                if (continueIndex > 0)
                {
                    continueTime = Time.time + (continueIndex / KickStarter.speechManager.textScrollSpeed);
                }

                if (speechGaps.Count > 0)
                {
                    displayText = log.fullText.Substring(0, speechGaps[0].characterIndex);
                }
                else
                {
                    displayText = log.fullText;
                }
            }
            else
            {
                displayText = "";
            }

            isAlive     = true;
            isSkippable = true;
            pauseGap    = false;
            endTime     = Time.time + displayDuration;
        }