/// <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); } }
/// <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 (CheckDontBarkDuringConversation()) { yield break; } if ((subtitle == null) || (subtitle.speakerInfo == null)) { yield break; } 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); 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 = PlayBarkSequence(subtitle, speaker, listener); 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 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, bool stopAtFirstValid = false) { if (CheckDontBarkDuringConversation()) { yield break; } bool barked = false; 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) { speaker = DialogueManager.instance.FindActorTransformFromConversation(conversationTitle, "Actor"); } 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 = 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, conversationTitle }), speaker); } var firstValid = stopAtFirstValid || ((barkHistory == null) ? false : barkHistory.order == (BarkOrder.FirstValid)); ConversationModel conversationModel = new ConversationModel(database ?? DialogueManager.masterDatabase, conversationTitle, speaker, listener, DialogueManager.allowLuaExceptions, DialogueManager.isDialogueEntryValid, -1, firstValid); 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 != null) && !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 { 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", new System.Object[] { DialogueDebug.Prefix, speaker, listener, conversationTitle }), speaker); } if (barkEntry != null) { var priority = GetEntryBarkPriority(barkEntry); 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, conversationTitle }), speaker); } yield break; } SetSpeakerCurrentBarkPriority(speaker, priority); barked = true; InformParticipants(DialogueSystemMessages.OnBarkStart, speaker, listener); ConversationState barkState = conversationModel.GetState(barkEntry, false); if (barkState == null) { if (DialogueDebug.logWarnings) { Debug.LogWarning(string.Format("{0}: Bark (speaker={1}, listener={2}): '{3}' can't find a valid dialogue entry", new System.Object[] { DialogueDebug.Prefix, speaker, listener, conversationTitle }), speaker); } yield break; } 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}'", new System.Object[] { DialogueDebug.Prefix, speaker, listener, barkState.subtitle.formattedText.text }), speaker); } InformParticipantsLine(DialogueSystemMessages.OnBarkLine, speaker, barkState.subtitle); // 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); } // Start the sequence: var sequencer = PlayBarkSequence(barkState.subtitle, speaker, listener); 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); } } } finally { if (barked) { 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 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); }
/// <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); } } }