protected virtual void DoBarkAction(Transform actor) { switch (barkSource) { case BarkSource.Conversation: if (string.IsNullOrEmpty(barkConversation)) { return; } if (DialogueManager.isConversationActive && !allowBarksDuringConversations) { if (DialogueDebug.logWarnings) { Debug.LogWarning("Dialogue System: Bark triggered on " + name + ", but a conversation is already active.", GetBarker(barkConversation)); } } else if (cacheBarkLines) { BarkCachedLine(GetBarker(barkConversation), Tools.Select(barkTarget, actor)); } else { if (barkGroupMember != null) { barkGroupMember.GroupBark(barkConversation, Tools.Select(barkTarget, actor), barkHistory); } else { DialogueManager.Bark(barkConversation, GetBarker(barkConversation), Tools.Select(barkTarget, actor), barkHistory); } sequencer = BarkController.LastSequencer; } break; case BarkSource.Text: if (string.IsNullOrEmpty(barkText)) { return; } if (DialogueManager.isConversationActive && !allowBarksDuringConversations) { if (DialogueDebug.logWarnings) { Debug.LogWarning("Dialogue System: Bark triggered on " + name + ", but a conversation is already active.", GetBarker(null)); } } else { if (barkGroupMember != null) { barkGroupMember.GroupBarkString(barkText, Tools.Select(barkTarget, actor), barkTextSequence); } else { DialogueManager.BarkString(barkText, GetBarker(null), Tools.Select(barkTarget, actor), barkTextSequence); } sequencer = BarkController.LastSequencer; } break; } }
/// <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(); }
/// <summary> /// Attempts to make a character bark. This is a coroutine; you must start it using /// StartCoroutine() or Unity will hang. Shows a specific subtitle and plays the sequence, /// but does not send OnBarkStart/OnBarkEnd messages to the participants. /// </summary> /// <param name='subtitle'> /// Subtitle to bark. /// </param> /// <param name='skipSequence'> /// If `true`, don't play the sequence associated with the subtitle. /// </param> public static IEnumerator Bark(Subtitle subtitle, bool skipSequence = false) { if (CheckDontBarkDuringConversation()) { yield break; } if ((subtitle == null) || (subtitle.speakerInfo == null)) { yield break; } Transform speaker = subtitle.speakerInfo.transform; Transform listener = (subtitle.listenerInfo != null) ? subtitle.listenerInfo.transform : null; var priority = GetEntryBarkPriority(subtitle.dialogueEntry); if (priority < GetSpeakerCurrentBarkPriority(speaker)) { if (DialogueDebug.logInfo) { Debug.Log(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' currently barking a higher priority bark", new System.Object[] { DialogueDebug.Prefix, speaker, listener, subtitle.formattedText.text }), speaker); } yield break; } SetSpeakerCurrentBarkPriority(speaker, priority); InformParticipants(DialogueSystemMessages.OnBarkStart, speaker, listener); InformParticipantsLine(DialogueSystemMessages.OnBarkLine, speaker, subtitle); IBarkUI barkUI = speaker.GetComponentInChildren(typeof(IBarkUI)) as IBarkUI; if ((barkUI == null) && DialogueDebug.logWarnings) { Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' speaker has no bark UI", new System.Object[] { DialogueDebug.Prefix, speaker, listener, subtitle.formattedText.text }), speaker); } if (((barkUI == null) || !(barkUI as MonoBehaviour).enabled) && DialogueDebug.logWarnings) { Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' bark UI is null or disabled", new System.Object[] { DialogueDebug.Prefix, speaker, listener, subtitle.formattedText.text }), speaker); } // Show the bark subtitle: if ((barkUI != null) && (barkUI as MonoBehaviour).enabled) { barkUI.Bark(subtitle); } // Start the sequence: Sequencer sequencer = null; if (!(skipSequence || string.IsNullOrEmpty(subtitle.sequence))) { sequencer = DialogueManager.PlaySequence(subtitle.sequence, speaker, listener, false, false, subtitle.entrytag); } LastSequencer = sequencer; // Wait until the sequence and subtitle are done: while (((sequencer != null) && sequencer.isPlaying) || ((barkUI != null) && barkUI.isPlaying)) { yield return(null); } if (sequencer != null) { GameObject.Destroy(sequencer); } InformParticipants(DialogueSystemMessages.OnBarkEnd, speaker, listener); SetSpeakerCurrentBarkPriority(speaker, 0); }
public override void OnRestartGame() { DialogueManager.ResetDatabase(); }
/// <summary> /// Barks a subtitle. Does not observe formatting codes in the subtitle's FormattedText, /// instead using the formatting settings defined on this component. /// </summary> /// <param name='subtitle'> /// Subtitle to bark. /// </param> public override void Bark(Subtitle subtitle) { if (ShouldShowText(subtitle)) { SetUIElementsActive(false); string subtitleText = subtitle.formattedText.text; if (includeName) { if (nameText != null) { nameText.text = subtitle.speakerInfo.Name; } else { subtitleText = string.Format("{0}: {1}", subtitleText, subtitle.formattedText.text); } } else { if (nameText != null && nameText.gameObject != null) { nameText.gameObject.SetActive(false); } } if (showPortraitImage && subtitle.speakerInfo.portrait != null) { Tools.SetGameObjectActive(portraitImage, true); portraitImage.sprite = subtitle.speakerInfo.portrait; } else { Tools.SetGameObjectActive(portraitImage, false); } if (barkText != null) { barkText.text = subtitleText; } SetUIElementsActive(true); if (CanTriggerAnimations() && !string.IsNullOrEmpty(animationTransitions.showTrigger)) { animator.SetTrigger(animationTransitions.showTrigger); } if (typewriter != null) { typewriter.StartTyping(subtitleText); } CancelInvoke("Hide"); var barkDuration = Mathf.Approximately(0, duration) ? DialogueManager.GetBarkDuration(subtitleText) : duration; if (!(waitUntilSequenceEnds || waitForContinueButton)) { Invoke("Hide", barkDuration); } if (waitUntilSequenceEnds) { numSequencesActive++; } doneTime = waitForContinueButton ? Mathf.Infinity : (DialogueTime.time + barkDuration); } }
private string GetUseMessage() { return(DialogueManager.GetLocalizedText(string.IsNullOrEmpty(usable.overrideUseMessage) ? defaultUseMessage : usable.overrideUseMessage)); }
/// <summary> /// Runs a raycast to see what's under the selection point. Updates the selection and /// calls the selection delegates if the selection has changed. If the player hits the /// use button, sends an OnUse message to the selection. /// </summary> protected virtual void Update() { // Exit if disabled or paused: if (!enabled || (Time.timeScale <= 0)) { return; } // Exit if there's no camera: if (UnityEngine.Camera.main == null) { return; } // Exit if using mouse selection and is over a UI element: if ((selectAt == SelectAt.MousePosition) && (UnityEngine.EventSystems.EventSystem.current != null) && UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) { return; } // Raycast 2D or 3D: switch (runRaycasts) { case Dimension.In2D: Run2DRaycast(); break; default: case Dimension.In3D: Run3DRaycast(); break; } // If the player presses the use key/button on a target: if (IsUseButtonDown() && (usable != null)) { clickedDownOn = null; if (distance <= usable.maxUseDistance) { // If within range, send the OnUse message: var fromTransform = (actorTransform != null) ? actorTransform : this.transform; if (broadcastToChildren) { usable.gameObject.BroadcastMessage("OnUse", fromTransform, SendMessageOptions.DontRequireReceiver); } else { usable.gameObject.SendMessage("OnUse", fromTransform, SendMessageOptions.DontRequireReceiver); } } else { // Otherwise report too far if configured to do so: if (!string.IsNullOrEmpty(tooFarMessage)) { DialogueManager.ShowAlert(tooFarMessage); } tooFarEvent.Invoke(); } } }
private IEnumerator LoadLevelFromSaveData(string saveData) { if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager: Starting LoadLevelFromSaveData coroutine"); } string levelName = defaultStartingLevel; if (string.IsNullOrEmpty(saveData)) { // If no saveData, reset the database. if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager: Save data is empty, so just resetting database"); } DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault); } else { // Put saveData in Lua so we can get Variable["SavedLevelName"]: if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager: Applying save data to get value of 'SavedLevelName' variable"); } Lua.Run(saveData, DialogueDebug.logInfo); levelName = DialogueLua.GetVariable("SavedLevelName").asString; if (string.IsNullOrEmpty(levelName) || string.Equals(levelName, "nil")) { levelName = defaultStartingLevel; if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager: 'SavedLevelName' isn't defined. Using default level " + levelName); } } else { if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager: SavedLevelName = " + levelName); } } } // Load the level: PersistentDataManager.LevelWillBeUnloaded(); if (CanLoadAsync()) { AsyncOperation async = Tools.LoadLevelAsync(levelName); isLoading = true; while (!async.isDone) { yield return(null); } isLoading = false; } else { Tools.LoadLevel(levelName); } // Wait two frames for objects in the level to finish their Start() methods: if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager finished loading level " + levelName + ". Waiting 2 frames for scene objects to start."); } yield return(null); yield return(null); // Then apply saveData to the objects: if (!string.IsNullOrEmpty(saveData)) { if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager waited 2 frames. Appling save data: " + saveData); } PersistentDataManager.ApplySaveData(saveData); } // Update quest tracker HUD: DialogueManager.SendUpdateTracker(); }
/// <summary> /// Resets the Lua environment -- for example, when starting a new game. /// </summary> /// <param name='databaseResetOptions'> /// The database reset options can be: /// /// - RevertToDefault: Removes all but the default database, then resets it. /// - KeepAllLoaded: Keeps all loaded databases in memory and just resets them. /// </param> public static void Reset(DatabaseResetOptions databaseResetOptions) { DialogueManager.ResetDatabase(databaseResetOptions); }
void Update() { if (runtimeQuestLogWindow == null) { return; } if (DialogueManager.IsDialogueSystemInputDisabled()) { return; } if (InputDeviceManager.IsKeyDown(key) || (!string.IsNullOrEmpty(buttonName) && DialogueManager.getInputButtonDown(buttonName))) { if (runtimeQuestLogWindow.isOpen) { runtimeQuestLogWindow.Close(); } else { runtimeQuestLogWindow.Open(); } } }