/// <summary> /// Handles the finished subtitle event. If the current conversation state has an NPC /// response, the conversation proceeds to that response. Otherwise, if the current /// state has PC responses, then the response menu is shown (or if it has a single /// auto-response, the conversation proceeds directly to that response). If there are no /// responses, the conversation ends. /// </summary> /// <param name='sender'> /// Sender. /// </param> /// <param name='e'> /// Event args. /// </param> public void OnFinishedSubtitle(object sender, EventArgs e) { var randomize = randomizeNextEntry; randomizeNextEntry = false; if (m_state.hasNPCResponse) { GotoState(m_model.GetState(randomize ? m_state.GetRandomNPCEntry() : m_state.firstNPCResponse.destinationEntry)); } else if (m_state.hasPCResponses) { bool isPCResponseMenuNext, isPCAutoResponseNext; AnalyzePCResponses(m_state, out isPCResponseMenuNext, out isPCAutoResponseNext); if (isPCAutoResponseNext) { GotoState(m_model.GetState(m_state.pcAutoResponse.destinationEntry)); } else { m_view.StartResponses(m_state.subtitle, m_state.pcResponses); } } else { Close(); } }
/// <summary> /// Handles the finished subtitle event. If the current conversation state has an NPC /// response, the conversation proceeds to that response. Otherwise, if the current /// state has PC responses, then the response menu is shown (or if it has a single /// auto-response, the conversation proceeds directly to that response). If there are no /// responses, the conversation ends. /// </summary> /// <param name='sender'> /// Sender. /// </param> /// <param name='e'> /// Event args. /// </param> private void OnFinishedSubtitle(object sender, EventArgs e) { if (state.HasNPCResponse) { GotoState(model.GetState(state.FirstNPCResponse.destinationEntry)); } else if (state.HasPCResponses) { if (state.HasPCAutoResponse && (!alwaysForceResponseMenu || state.pcResponses[0].destinationEntry.isGroup)) { GotoState(model.GetState(state.PCAutoResponse.destinationEntry)); } else { view.StartResponses(state.subtitle, state.pcResponses); } } else { Close(); } }
/// <summary> /// Handles the finished subtitle event. If the current conversation state has an NPC /// response, the conversation proceeds to that response. Otherwise, if the current /// state has PC responses, then the response menu is shown (or if it has a single /// auto-response, the conversation proceeds directly to that response). If there are no /// responses, the conversation ends. /// </summary> /// <param name='sender'> /// Sender. /// </param> /// <param name='e'> /// Event args. /// </param> private void OnFinishedSubtitle(object sender, EventArgs e) { if (state.hasNPCResponse) { GotoState(m_model.GetState(state.firstNPCResponse.destinationEntry)); } else if (state.hasPCResponses) { bool isPCResponseMenuNext, isPCAutoResponseNext; AnalyzePCResponses(state, out isPCResponseMenuNext, out isPCAutoResponseNext); if (isPCAutoResponseNext) { GotoState(m_model.GetState(state.pcAutoResponse.destinationEntry)); } else { m_view.StartResponses(state.subtitle, state.pcResponses); } } else { Close(); } }
/// <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 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 (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); 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 { 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", new System.Object[] { DialogueDebug.Prefix, speaker, listener, conversationTitle }), speaker); if (barkEntry != null) { 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); // 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); } } }
/// <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); } } }