/// <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. This optimized version /// </summary> /// <param name='subtitle'> /// Subtitle to bark. /// </param> /// <param name='speaker'> /// Speaker performing the bark. /// </param> /// <param name='listener'> /// Listener that the bark is directed to; may be <c>null</c>. /// </param> /// <param name='barkUI'> /// The bark UI to bark with. /// </param> public static IEnumerator Bark(Subtitle subtitle, Transform speaker, Transform listener, IBarkUI barkUI) { if ((subtitle == null) || (subtitle.speakerInfo == null)) { yield break; } 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); } if ((barkUI != null) && (barkUI as MonoBehaviour).enabled) { barkUI.Bark(subtitle); } Sequencer sequencer = null; if (!string.IsNullOrEmpty(subtitle.sequence)) { sequencer = DialogueManager.PlaySequence(subtitle.sequence, speaker, listener, false, false); sequencer.entrytag = subtitle.entrytag; } LastSequencer = sequencer; while (((sequencer != null) && sequencer.IsPlaying) || ((barkUI != null) && barkUI.IsPlaying)) { yield return(null); } if (sequencer != null) { GameObject.Destroy(sequencer); } }
// 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 speaker = (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 <PlaySequenceBehaviour> inputPlayable = (ScriptPlayable <PlaySequenceBehaviour>)playable.GetInput(i); PlaySequenceBehaviour input = inputPlayable.GetBehaviour(); var sequence = input.sequence; if (Application.isPlaying) { DialogueManager.PlaySequence(sequence, speaker, input.listener); } else { PreviewUI.ShowMessage(sequence, 3, -1); } } else if (inputWeight <= 0.001f && played.Contains(i)) { played.Remove(i); } } }
protected virtual void DoSequenceAction(Transform actor) { if (string.IsNullOrEmpty(sequence)) { return; } DialogueManager.PlaySequence(sequence, Tools.Select(sequenceSpeaker, transform), Tools.Select(sequenceListener, actor)); }
public void DoAction(SequenceAction action, Transform actor) { if (action != null) { Transform sequenceActor = Tools.Select(action.actor, this.transform); Transform otherParticipant = Tools.Select(action.otherParticipant, actor); DialogueManager.PlaySequence(action.sequence, sequenceActor, otherParticipant); } }
/// <summary> /// Call this method to manually run the action. /// </summary> public void Fire() { // Quest: if (!string.IsNullOrEmpty(questName)) { QuestLog.SetQuestState(questName, questState); } // Lua: if (!string.IsNullOrEmpty(luaCode)) { Lua.Run(luaCode, DialogueDebug.logInfo); DialogueManager.CheckAlerts(); } // Sequence: if (!string.IsNullOrEmpty(sequence)) { DialogueManager.PlaySequence(sequence); } // Alert: if (!string.IsNullOrEmpty(alertMessage)) { string localizedAlertMessage; if ((textTable != null) && textTable.HasFieldTextForLanguage(alertMessage, Localization.GetCurrentLanguageID(textTable))) { localizedAlertMessage = textTable.GetFieldTextForLanguage(alertMessage, Localization.GetCurrentLanguageID(textTable)); } else { localizedAlertMessage = DialogueManager.GetLocalizedText(alertMessage); } DialogueManager.ShowAlert(localizedAlertMessage); } // Send Messages: foreach (var sma in sendMessages) { if (sma.gameObject != null && !string.IsNullOrEmpty(sma.message)) { sma.gameObject.SendMessage(sma.message, sma.parameter, SendMessageOptions.DontRequireReceiver); } } DialogueManager.SendUpdateTracker(); if (once) { StopObserving(); enabled = false; } }
/// <summary> /// Your GUI should call this when the player confirms abandonment of a quest. /// </summary> private void OnConfirmAbandonQuest() { QuestLog.SetQuestState(SelectedQuest, abandonQuestState); ShowQuests(currentQuestStateMask); DialogueManager.Instance.BroadcastMessage("OnQuestTrackingDisabled", SelectedQuest, SendMessageOptions.DontRequireReceiver); string sequence = QuestLog.GetQuestAbandonSequence(SelectedQuest); if (!string.IsNullOrEmpty(sequence)) { DialogueManager.PlaySequence(sequence); } }
/// <summary> /// Your GUI should call this when the player confirms abandonment of a quest. /// </summary> protected virtual void OnConfirmAbandonQuest() { QuestLog.SetQuestState(selectedQuest, abandonQuestState); selectedQuest = string.Empty; ShowQuests(currentQuestStateMask); DialogueManager.instance.BroadcastMessage(DialogueSystemMessages.OnQuestTrackingDisabled, selectedQuest, SendMessageOptions.DontRequireReceiver); string sequence = QuestLog.GetQuestAbandonSequence(selectedQuest); if (!string.IsNullOrEmpty(sequence)) { DialogueManager.PlaySequence(sequence); } }
/// <summary> /// Starts the sequence if the condition is true. /// </summary> public void TryStartSequence(Transform actor) { if (tryingToStart) { return; } tryingToStart = true; try { if (((condition == null) || condition.IsTrue(actor)) && !string.IsNullOrEmpty(sequence)) { DialogueManager.PlaySequence(sequence, Tools.Select(speaker, this.transform), Tools.Select(listener, actor)); DestroyIfOnce(); } } finally { tryingToStart = false; } }
private static Sequencer PlayBarkSequence(Subtitle subtitle, Transform speaker, Transform listener) { if (!string.IsNullOrEmpty(subtitle.sequence)) { var sequence = Sequencer.ReplaceShortcuts(subtitle.sequence); if (sequence.Contains(SequencerKeywords.End)) { var text = subtitle.formattedText.text; int numCharacters = string.IsNullOrEmpty(text) ? 0 : Tools.StripRichTextCodes(text).Length; var endDuration = Mathf.Max(DialogueManager.displaySettings.GetMinSubtitleSeconds(), numCharacters / Mathf.Max(1, DialogueManager.displaySettings.GetSubtitleCharsPerSecond())); sequence = sequence.Replace(SequencerKeywords.End, endDuration.ToString(System.Globalization.CultureInfo.InvariantCulture)); } return(DialogueManager.PlaySequence(sequence, speaker, listener, false, false, subtitle.entrytag)); } else { return(null); } }
/// <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 = DialogueActor.GetBarkUI(speaker); // 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); }
/// <summary> /// Attempts to make a character bark. This is a coroutine; you must start it using /// StartCoroutine() or Unity will hang. Shows a line from the named conversation, plays /// the sequence, and sends OnBarkStart/OnBarkEnd messages to the participants. /// </summary> /// <param name='conversationTitle'> /// Title of conversation to pull bark lines from. /// </param> /// <param name='speaker'> /// Speaker performing the bark. /// </param> /// <param name='listener'> /// Listener that the bark is directed to; may be <c>null</c>. /// </param> /// <param name='barkHistory'> /// Bark history used to keep track of the most recent bark so this method can iterate /// through them in a specified order. /// </param> /// <param name='database'> /// The dialogue database to use. If <c>null</c>, uses DialogueManager.MasterDatabase. /// </param> public static IEnumerator Bark(string conversationTitle, Transform speaker, Transform listener, BarkHistory barkHistory, DialogueDatabase database = null) { if (string.IsNullOrEmpty(conversationTitle) && DialogueDebug.LogWarnings) { Debug.Log(string.Format("{0}: Bark (speaker={1}, listener={2}): conversation title is blank", new System.Object[] { DialogueDebug.Prefix, speaker, listener }), speaker); } if ((speaker == null) && DialogueDebug.LogWarnings) { Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' speaker is null", new System.Object[] { DialogueDebug.Prefix, speaker, listener, conversationTitle })); } if (string.IsNullOrEmpty(conversationTitle) || (speaker == null)) { yield break; } 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, conversationTitle }), speaker); } ConversationModel conversationModel = new ConversationModel(database ?? DialogueManager.MasterDatabase, conversationTitle, speaker, listener, DialogueManager.AllowLuaExceptions, DialogueManager.IsDialogueEntryValid); ConversationState firstState = conversationModel.FirstState; if ((firstState == null) && DialogueDebug.LogWarnings) { Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' has no START entry", new System.Object[] { DialogueDebug.Prefix, speaker, listener, conversationTitle }), speaker); } if (!firstState.HasAnyResponses && DialogueDebug.LogWarnings) { Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' has no valid bark at this time", new System.Object[] { DialogueDebug.Prefix, speaker, listener, conversationTitle }), speaker); } if ((firstState != null) && firstState.HasAnyResponses) { try { InformParticipants("OnBarkStart", speaker, listener); Response[] responses = firstState.HasNPCResponse ? firstState.npcResponses : firstState.pcResponses; int index = (barkHistory ?? new BarkHistory(BarkOrder.Random)).GetNextIndex(responses.Length); DialogueEntry barkEntry = responses[index].destinationEntry; if ((barkEntry == null) && DialogueDebug.LogWarnings) { Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' bark entry is null", DialogueDebug.Prefix, speaker, listener, conversationTitle), speaker); } if (barkEntry != null) { ConversationState barkState = conversationModel.GetState(barkEntry, false); if (firstState.HasNPCResponse) { CharacterInfo tempInfo = barkState.subtitle.speakerInfo; barkState.subtitle.speakerInfo = barkState.subtitle.listenerInfo; barkState.subtitle.listenerInfo = tempInfo; } if (DialogueDebug.LogInfo) { Debug.Log(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}'", DialogueDebug.Prefix, speaker, listener, barkState.subtitle.formattedText.text), speaker); } // Show the bark subtitle: 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, barkState.subtitle.formattedText.text }), speaker); } if ((barkUI != null) && (barkUI as MonoBehaviour).enabled) { barkUI.Bark(barkState.subtitle); } // Run Lua: if (!string.IsNullOrEmpty(barkState.subtitle.dialogueEntry.userScript)) { Lua.Run(barkState.subtitle.dialogueEntry.userScript, DialogueDebug.LogInfo, false); } // Play the sequence: Sequencer sequencer = null; if (!string.IsNullOrEmpty(barkState.subtitle.sequence)) { sequencer = DialogueManager.PlaySequence(barkState.subtitle.sequence, speaker, listener, false, false); sequencer.entrytag = barkState.subtitle.entrytag; } LastSequencer = sequencer; while (((sequencer != null) && sequencer.IsPlaying) || ((barkUI != null) && barkUI.IsPlaying)) { yield return(null); } if (sequencer != null) { GameObject.Destroy(sequencer); } } } finally { InformParticipants("OnBarkEnd", speaker, listener); } } }