protected System.Collections.IEnumerator StartSavedConversation(Data data)
        {
            var dialogueUI = DialogueManager.dialogueUI as StandardDialogueUI;

            DialogueManager.StopConversation();
            if (dialogueUI != null)
            {
                float safeguardTimeout = Time.realtimeSinceStartup + 5f;
                while (dialogueUI.isOpen && Time.realtimeSinceStartup < safeguardTimeout)
                {
                    yield return(null);
                }
            }
            var conversationID = data.conversationID;
            var entryID        = data.entryID;
            var conversation   = DialogueManager.masterDatabase.GetConversation(conversationID);
            var actorName      = DialogueLua.GetVariable("CurrentConversationActor").AsString;
            var conversantName = DialogueLua.GetVariable("CurrentConversationConversant").AsString;

            if (DialogueDebug.logInfo)
            {
                Debug.Log("Dialogue System: ConversationStateSaver is resuming conversation " + conversation.Title + " with actor=" + actorName + " and conversant=" + conversantName + " at entry " + entryID + ".", this);
            }
            var actor               = string.IsNullOrEmpty(actorName) ? null : GameObject.Find(actorName);
            var conversant          = string.IsNullOrEmpty(conversantName) ? null : GameObject.Find(conversantName);
            var actorTransform      = (actor != null) ? actor.transform : null;
            var conversantTransform = (conversant != null) ? conversant.transform : null;
            var ui = DialogueManager.dialogueUI as StandardDialogueUI;

            if (ui != null)
            {
                ui.conversationUIElements.standardSubtitleControls.QueueSavedActorPanelCache(data.actorGOs, data.actorGOPanels, data.actorIDs, data.actorIDPanels);
            }
            DialogueManager.StartConversation(conversation.Title, actorTransform, conversantTransform, entryID);
        }
        public virtual void OnApplyPersistentData()
        {
            if (!enabled)
            {
                return;
            }
            var conversationID = DialogueLua.GetVariable("CurrentConversationID").AsInt;
            var entryID        = DialogueLua.GetVariable("CurrentEntryID").AsInt;

            if (conversationID >= 0 && entryID > 0)
            {
                var conversation   = DialogueManager.MasterDatabase.GetConversation(conversationID);
                var actorName      = DialogueLua.GetVariable("CurrentConversationActor").AsString;
                var conversantName = DialogueLua.GetVariable("CurrentConversationConversant").AsString;
                if (DialogueDebug.logInfo)
                {
                    Debug.Log("Dialogue System: ConversationStateSaver is resuming conversation " + conversation.Title + " with actor=" + actorName + " and conversant=" + conversantName + " at entry " + entryID + ".", this);
                }
                var actor               = GameObject.Find(actorName);
                var conversant          = GameObject.Find(conversantName);
                var actorTransform      = (actor != null) ? actor.transform : null;
                var conversantTransform = (conversant != null) ? conversant.transform : null;
                DialogueManager.StopConversation();
                DialogueManager.StartConversation(conversation.Title, actorTransform, conversantTransform, entryID);
            }
        }
        public override void ApplyData(string s)
        {
            if (!enabled || string.IsNullOrEmpty(s))
            {
                return;
            }
            var data = SaveSystem.Deserialize <Data>(s);

            if (data == null)
            {
                return;
            }
            DialogueManager.StopConversation();
            var conversationID = data.conversationID;
            var entryID        = data.entryID;
            var conversation   = DialogueManager.masterDatabase.GetConversation(conversationID);
            var actorName      = DialogueLua.GetVariable("CurrentConversationActor").AsString;
            var conversantName = DialogueLua.GetVariable("CurrentConversationConversant").AsString;

            if (DialogueDebug.logInfo)
            {
                Debug.Log("Dialogue System: ConversationStateSaver is resuming conversation " + conversation.Title + " with actor=" + actorName + " and conversant=" + conversantName + " at entry " + entryID + ".", this);
            }
            var actor               = string.IsNullOrEmpty(actorName) ? null : GameObject.Find(actorName);
            var conversant          = string.IsNullOrEmpty(conversantName) ? null : GameObject.Find(conversantName);
            var actorTransform      = (actor != null) ? actor.transform : null;
            var conversantTransform = (conversant != null) ? conversant.transform : null;
            var ui = DialogueManager.dialogueUI as StandardDialogueUI;

            if (ui != null)
            {
                ui.conversationUIElements.standardSubtitleControls.QueueSavedActorPanelCache(data.actorGOs, data.actorGOPanels, data.actorIDs, data.actorIDPanels);
            }
            DialogueManager.StartConversation(conversation.Title, actorTransform, conversantTransform, entryID);
        }
 /// <summary>
 /// Executes a conversation action.
 /// </summary>
 public void DoAction(ConversationAction action, Transform actor)
 {
     if (action != null)
     {
         Transform speaker  = Tools.Select(action.speaker, this.transform);
         Transform listener = Tools.Select(action.listener, actor);
         bool      skip     = action.skipIfNoValidEntries && !DialogueManager.ConversationHasValidEntry(action.conversation, speaker, listener);
         if (!skip)
         {
             DialogueManager.StartConversation(action.conversation, speaker, listener);
         }
     }
 }
Beispiel #5
0
        protected virtual void DoConversationAction(Transform actor)
        {
            if (string.IsNullOrEmpty(conversation))
            {
                return;
            }
            if (exclusive && DialogueManager.isConversationActive)
            {
                if (DialogueDebug.logInfo)
                {
                    Debug.Log("Dialogue System: Conversation triggered on " + name + " but skipping because another conversation is active.", this);
                }
            }
            else
            {
                var actorTransform      = Tools.Select(conversationActor, actor);
                var conversantTransform = conversationConversant;
                if (conversantTransform == null)
                {
                    var conversationAsset           = DialogueManager.MasterDatabase.GetConversation(conversation);
                    var conversationConversantActor = (conversationAsset != null) ? DialogueManager.MasterDatabase.GetActor(conversationAsset.ConversantID) : null;
                    var registeredTransform         = (conversationConversantActor != null) ? CharacterInfo.GetRegisteredActorTransform(conversationConversantActor.Name) : null;
                    conversantTransform = (registeredTransform != null) ? registeredTransform : this.transform;
                }
                if (skipIfNoValidEntries && !DialogueManager.ConversationHasValidEntry(conversation, actorTransform, conversantTransform))
                {
                    if (DialogueDebug.logInfo)
                    {
                        Debug.Log("Dialogue System: Conversation triggered on " + name + " but skipping because no entries are currently valid.", this);
                    }
                }
                else
                {
                    if (stopConversationIfTooFar || showCursorDuringConversation || pauseGameDuringConversation)
                    { // Trigger may not be on actor or conversant, so we need to hook into these events:
                        DialogueManager.instance.conversationStarted += OnConversationStartAnywhere;
                        DialogueManager.instance.conversationEnded   += OnConversationEndAnywhere;
                    }

                    DialogueManager.StartConversation(conversation, actorTransform, conversantTransform, startConversationEntryID);
                    earliestTimeToAllowTriggerExit = Time.time + MarginToAllowTriggerExit;
                    if (stopConversationIfTooFar)
                    {
                        monitorDistanceCoroutine = StartCoroutine(MonitorDistance(DialogueManager.currentActor));
                    }
                }
            }
        }
        private void StartConversation(Transform actor)
        {
            Transform actualConversant = Tools.Select(conversant, this.transform);
            bool      skip             = skipIfNoValidEntries && !DialogueManager.ConversationHasValidEntry(conversation, actor, actualConversant);

            if (skip)
            {
                if (DialogueDebug.LogInfo)
                {
                    Debug.Log(string.Format("{0}: Conversation triggered on {1}, but skipping because no entries are currently valid.", new System.Object[] { DialogueDebug.Prefix, name }));
                }
            }
            else
            {
                DialogueManager.StartConversation(conversation, actor, actualConversant);
            }
        }
Beispiel #7
0
        // NOTE: This function is called at runtime and edit time.  Keep that in mind when setting the values of properties.
        public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            GameObject trackBinding = playerData as GameObject;

            if (!trackBinding)
            {
                return;
            }

            int inputCount = playable.GetInputCount();

            for (int i = 0; i < inputCount; i++)
            {
                float inputWeight = playable.GetInputWeight(i);
                if (inputWeight > 0.001f && !played.Contains(i))
                {
                    played.Add(i);
                    ScriptPlayable <StartConversationBehaviour> inputPlayable = (ScriptPlayable <StartConversationBehaviour>)playable.GetInput(i);
                    StartConversationBehaviour input = inputPlayable.GetBehaviour();
                    if (Application.isPlaying)
                    {
                        if (input.entryID <= 0)
                        {
                            DialogueManager.StartConversation(input.conversation, trackBinding.transform, input.conversant);
                        }
                        else
                        {
                            DialogueManager.StartConversation(input.conversation, trackBinding.transform, input.conversant, input.entryID);
                        }
                    }
                    else
                    {
                        var message = OverrideActorName.GetActorName(trackBinding.transform) + " conversation: " + input.conversant;
                        PreviewUI.ShowMessage(message, 2, 0);
                    }
                }
                else if (inputWeight <= 0.001f && played.Contains(i))
                {
                    played.Remove(i);
                }
            }
        }
        // NOTE: This function is called at runtime and edit time.  Keep that in mind when setting the values of properties.
        public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            GameObject trackBinding = playerData as GameObject;

            Transform actorTransform = (trackBinding != null) ? trackBinding.transform : null;

            int inputCount = playable.GetInputCount();

            for (int i = 0; i < inputCount; i++)
            {
                float inputWeight = playable.GetInputWeight(i);
                if (inputWeight > 0.001f && !played.Contains(i))
                {
                    played.Add(i);
                    ScriptPlayable <StartConversationBehaviour> inputPlayable = (ScriptPlayable <StartConversationBehaviour>)playable.GetInput(i);
                    StartConversationBehaviour input = inputPlayable.GetBehaviour();
                    if (Application.isPlaying)
                    {
                        if (input.jumpToSpecificEntry && input.entryID > 0)
                        {
                            DialogueManager.StartConversation(input.conversation, actorTransform, input.conversant, input.entryID);
                        }
                        else
                        {
                            DialogueManager.StartConversation(input.conversation, actorTransform, input.conversant);
                        }
                    }
                    else
                    {
                        var message = "Conversation (" + DialogueActor.GetActorName(actorTransform) + "->" + DialogueActor.GetActorName(input.conversant) + "): [" + input.conversation + "] '" + input.GetEditorDialogueText() + "' (may vary)";
                        PreviewUI.ShowMessage(message, 2, 0);
                    }
                }
                else if (inputWeight <= 0.001f && played.Contains(i))
                {
                    played.Remove(i);
                }
            }
        }
Beispiel #9
0
 protected virtual void DoConversationAction(Transform actor)
 {
     if (string.IsNullOrEmpty(conversation))
     {
         return;
     }
     if (skipIfNoValidEntries && !DialogueManager.ConversationHasValidEntry(conversation, Tools.Select(conversationActor, actor), Tools.Select(conversationConversant, this.transform)))
     {
         if (DialogueDebug.logInfo)
         {
             Debug.Log("Dialogue System: Conversation triggered on " + name + " but skipping because no entries are currently valid.", this);
         }
     }
     else if (exclusive && DialogueManager.isConversationActive)
     {
         if (DialogueDebug.logInfo)
         {
             Debug.Log("Dialogue System: Conversation triggered on " + name + " but skipping because another conversation is active.", this);
         }
     }
     else
     {
         var actorTransform      = Tools.Select(conversationActor, actor);
         var conversantTransform = conversationConversant;
         if (conversantTransform == null)
         {
             var conversationAsset           = DialogueManager.MasterDatabase.GetConversation(conversation);
             var conversationConversantActor = DialogueManager.MasterDatabase.GetActor(conversationAsset.ConversantID);
             var registeredTransform         = (conversationConversantActor != null) ? CharacterInfo.GetRegisteredActorTransform(conversationConversantActor.Name) : null;
             conversantTransform = (registeredTransform != null) ? registeredTransform : this.transform;
         }
         DialogueManager.StartConversation(conversation, actorTransform, conversantTransform);
         earliestTimeToAllowTriggerExit = Time.time + MarginToAllowTriggerExit;
         if (stopConversationIfTooFar)
         {
             monitorDistanceCoroutine = StartCoroutine(MonitorDistance(actor));
         }
     }
 }
        /// <summary>
        /// When loading a game, load the dialogue entry records and resume the conversation.
        /// </summary>
        public virtual void OnApplyPersistentData()
        {
            if (DontLoadInThisScene())
            {
                Debug.Log("OnApplyPersistentData Dont Load in this scene: " + SceneManager.GetActiveScene().buildIndex);
            }
            if (DontLoadInThisScene())
            {
                return;
            }
            records.Clear();
            if (!DialogueLua.DoesVariableExist(currentDialogueEntryRecords))
            {
                return;
            }
            StopAllCoroutines();

            // Load dialogue entry records:
            var s = DialogueLua.GetVariable(currentDialogueEntryRecords).AsString;

            if (Debug.isDebugBuild)
            {
                Debug.Log("TextlineDialogueUI.OnApplyPersistentData: Restoring current conversation from " + currentDialogueEntryRecords + ": " + s);
            }
            var ints       = s.Split(';');
            var numRecords = Tools.StringToInt(ints[0]);

            for (int i = 0; i < numRecords; i++)
            {
                var conversationID = Tools.StringToInt(ints[1 + i * 2]);
                var entryID        = Tools.StringToInt(ints[2 + i * 2]);
                records.Add(new DialogueEntryRecord(conversationID, entryID));
            }

            // If we have records, resume the conversation:
            if (records.Count == 0)
            {
                return;
            }
            var lastRecord = records[records.Count - 1];

            if (lastRecord.conversationID >= 0 && lastRecord.entryID > 0)
            {
                UnityEngine.UI.Button lastContinueButton = null;
                try
                {
                    // Resume conversation:
                    //if (dontRepeatLastSequence) isLoadingGame = true;
                    isLoadingGame = true;
                    var conversation        = DialogueManager.MasterDatabase.GetConversation(lastRecord.conversationID);
                    var actorName           = DialogueLua.GetVariable(currentConversationActor).AsString;
                    var conversantName      = DialogueLua.GetVariable(currentConversationConversant).AsString;
                    var actor               = GameObject.Find(actorName);
                    var conversant          = GameObject.Find(conversantName);
                    var actorTransform      = (actor != null) ? actor.transform : null;
                    var conversantTransform = (conversant != null) ? conversant.transform : null;
                    if (Debug.isDebugBuild)
                    {
                        Debug.Log("Resuming '" + conversation.Title + "' at entry " + lastRecord.entryID);
                    }
                    DialogueManager.StopConversation();
                    var lastEntry        = DialogueManager.MasterDatabase.GetDialogueEntry(lastRecord.conversationID, lastRecord.entryID);
                    var originalSequence = lastEntry.Sequence; // Handle last entry's sequence differently if end entry.
                    npcPreDelaySettings.CopyTo(npcPreDelaySettingsCopy);
                    pcPreDelaySettings.CopyTo(pcPreDelaySettingsCopy);
                    npcPreDelaySettings.basedOnTextLength = false;
                    npcPreDelaySettings.additionalSeconds = 0;
                    pcPreDelaySettings.basedOnTextLength  = false;
                    pcPreDelaySettings.additionalSeconds  = 0;
                    var isEndEntry = lastEntry.Sequence.Contains("WaitForMessage(Forever)") || lastEntry.outgoingLinks.Count == 0;
                    if (isEndEntry)
                    {
                        if (!lastEntry.Sequence.Contains("WaitForMessage(Forever)"))
                        {
                            lastEntry.Sequence = "WaitForMessage(Forever); " + lastEntry.Sequence;
                        }
                    }
                    else if (dontRepeatLastSequence)
                    {
                        lastEntry.Sequence = "None()";
                    }
                    else
                    {
                        lastEntry.Sequence = "Delay(0.1)";
                    }
                    skipNextRecord = true;
                    isInPreDelay   = false;
                    DialogueManager.StartConversation(conversation.Title, actorTransform, conversantTransform, lastRecord.entryID);
                    lastContinueButton = continueButton;
                    lastEntry.Sequence = originalSequence;
                    npcPreDelaySettingsCopy.CopyTo(npcPreDelaySettings);
                    pcPreDelaySettingsCopy.CopyTo(pcPreDelaySettings);

                    // Populate UI with previous records:
                    var lastInstance = (instantiatedMessages.Count > 0) ? instantiatedMessages[instantiatedMessages.Count - 1] : null;
                    instantiatedMessages.Remove(lastInstance);
                    DestroyInstantiatedMessages();
                    for (int i = 0; i < records.Count - 1; i++)
                    {
                        var entry         = DialogueManager.MasterDatabase.GetDialogueEntry(records[i].conversationID, records[i].entryID);
                        var speakerInfo   = DialogueManager.ConversationModel.GetCharacterInfo(entry.ActorID);
                        var listenerInfo  = DialogueManager.ConversationModel.GetCharacterInfo(entry.ConversantID);
                        var formattedText = FormattedText.Parse(entry.currentDialogueText, DialogueManager.MasterDatabase.emphasisSettings);
                        var subtitle      = new Subtitle(speakerInfo, listenerInfo, null, formattedText, "None()", entry.ResponseMenuSequence, entry);
                        AddMessage(subtitle);
                    }
                    if (lastInstance != null)
                    {
                        instantiatedMessages.Add(lastInstance);
                        lastInstance.transform.SetAsLastSibling();
                    }
                }
                finally
                {
                    isLoadingGame = false;
                    scrollRect.verticalNormalizedPosition = 0;
                    continueButton = lastContinueButton;
                    if (shouldShowContinueButton && lastContinueButton != null)
                    {
                        lastContinueButton.gameObject.SetActive(true);
                    }
                }
            }
            ScrollToBottom();
        }