/// <summary> /// Shows a subtitle. Opens a subtitle panel and sets the content. If the speaker /// has a DialogueActor component, this may dictate which panel opens. /// </summary> /// <param name="subtitle">Subtitle to show.</param> public override void ShowSubtitle(Subtitle subtitle) { if (subtitle == null) { return; } DialogueActor dialogueActor; var panel = GetPanel(subtitle, out dialogueActor); if (SubtitleUsesBarkUI(subtitle)) { DialogueManager.BarkString(subtitle.formattedText.text, subtitle.speakerInfo.transform, subtitle.listenerInfo.transform, subtitle.sequence); } else if (panel == null) { if (DialogueDebug.logWarnings) { Debug.LogWarning("Dialogue System: Can't find subtitle panel for " + GetSubtitleTextSummary(subtitle) + "."); } } else if (string.IsNullOrEmpty(subtitle.formattedText.text)) { HideSubtitle(subtitle); } else { // If actor is currently displaying on another panel, close that panel: var actorID = subtitle.speakerInfo.id; if (m_lastPanelUsedByActor.ContainsKey(actorID) && m_lastPanelUsedByActor[actorID] != panel) { var previousPanel = m_lastPanelUsedByActor[actorID]; if (m_lastActorToUsePanel.ContainsKey(previousPanel) && m_lastActorToUsePanel[previousPanel] == actorID) { if (previousPanel.hasFocus) { previousPanel.Unfocus(); } if (previousPanel.isOpen) { previousPanel.Close(); } } } m_lastActorToUsePanel[panel] = actorID; m_lastPanelUsedByActor[actorID] = panel; // Focus the panel and show the subtitle: m_focusedPanel = panel; if (panel.addSpeakerName) { subtitle.formattedText.text = string.Format(panel.addSpeakerNameFormat, new object[] { subtitle.speakerInfo.Name, subtitle.formattedText.text }); } if (dialogueActor != null && dialogueActor.standardDialogueUISettings.setSubtitleColor) { subtitle.formattedText.text = dialogueActor.AdjustSubtitleColor(subtitle); } panel.ShowSubtitle(subtitle); SupercedeOtherPanels(panel); } }
/// <summary> /// Barks with group awareness. /// </summary> /// <param name="barkText">Text to bark.</param> /// <param name="member">Barker.</param> /// <param name="listener">Bark target.</param> /// <param name="sequence">Optional sequence to play during the bark.</param> /// <param name="delayTime">Omit/zero to use the member's random delay settings; if nonzero, use this delay time.</param> public void GroupBarkString(string barkText, BarkGroupMember member, Transform listener, string sequence, float delayTime = 0) { if (member == null || !member.queueBarks) { DialogueManager.BarkString(barkText, (member != null) ? member.transform : null, listener, sequence); } else { Enqueue(new BarkRequest(barkText, member, listener, sequence, delayTime)); } }
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 { 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 { DialogueManager.BarkString(barkText, GetBarker(null), Tools.Select(barkTarget, actor), barkTextSequence); sequencer = BarkController.LastSequencer; } break; } }
private void Update() { // Check each group's queue: var enumerator = queues.GetEnumerator(); // Enumerates manually to avoid garbage. while (enumerator.MoveNext()) { var queue = enumerator.Current.Value; if (queue.Count == 0) { continue; } var barkRequest = queue.Peek(); if (!barkRequest.isPlaying) { // If request at front of queue isn't playing yet, update time left: barkRequest.delayTime -= Time.deltaTime; if (barkRequest.delayTime <= 0) { // If it's now time, play the bark: if (barkRequest.member == null || barkRequest.barkUI == null || (string.IsNullOrEmpty(barkRequest.conversation) && string.IsNullOrEmpty(barkRequest.barkText))) { queue.Dequeue(); } else if (!string.IsNullOrEmpty(barkRequest.conversation)) { DialogueManager.Bark(barkRequest.conversation, barkRequest.member.transform, barkRequest.listener, barkRequest.barkHistory); } else { DialogueManager.BarkString(barkRequest.barkText, barkRequest.member.transform, barkRequest.listener, barkRequest.sequence); } barkRequest.isPlaying = true; barkRequest.delayTime = 0.5f; // Wait a little for bark to set up before checking if it's done playing. } } else { barkRequest.delayTime -= Time.deltaTime; if (barkRequest.delayTime <= 0 && !barkRequest.barkUI.isPlaying) { // If request at front of queue is playing but bark UI is done playing, dequeue: queue.Dequeue(); } } } }
// 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 <BarkBehaviour> inputPlayable = (ScriptPlayable <BarkBehaviour>)playable.GetInput(i); BarkBehaviour input = inputPlayable.GetBehaviour(); if (Application.isPlaying) { if (input.useConversation) { DialogueManager.Bark(input.conversation, trackBinding.transform, input.listener); } else { DialogueManager.BarkString(input.text, trackBinding.transform, input.listener); } } else { var message = DialogueActor.GetActorName(trackBinding.transform) + " bark: " + input.GetEditorBarkText(); if (input.useConversation) { message += " (may vary)"; } PreviewUI.ShowMessage(message, 2, 1); } } else if (inputWeight <= 0.001f && played.Contains(i)) { played.Remove(i); } } }