/// <summary> /// Listens for the OnApplyPersistentData message and retrieves the current bark index. /// </summary> public void OnApplyPersistentData() { if (enabled && !string.IsNullOrEmpty(barkConversation)) { if (barkHistory == null) { barkHistory = new BarkHistory(barkOrder); } barkHistory.index = DialogueLua.GetActorField(GetBarkerName(), "Bark_Index").asInt; } }
/// <summary> /// Listens for the OnApplyPersistentData message and retrieves the current bark index. /// </summary> public void OnApplyPersistentData() { if (enabled) { if (barkHistory == null) { barkHistory = new BarkHistory(barkOrder); } barkHistory.index = DialogueLua.GetActorField(GetBarkerName(), "Bark_Index").asInt; } }
public virtual void Awake() { barkHistory = new BarkHistory(barkOrder); sequencer = null; }
public void GroupBark(string conversation, Transform listener, BarkHistory barkHistory, float delayTime = -1) { BarkGroupManager.instance.GroupBark(conversation, this, listener, barkHistory, delayTime); }
/// <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> /// Causes a character to bark a line at another character. A bark is a line spoken outside /// of a full conversation. It uses a simple gameplay bark UI instead of the dialogue UI. /// </summary> /// <param name='conversationTitle'> /// Title of the conversation that contains the bark lines. In this conversation, all /// dialogue entries linked from the first entry are considered bark lines. /// </param> /// <param name='speaker'> /// The character barking the line. /// </param> /// <param name='listener'> /// The character being barked at. /// </param> /// <param name='barkHistory'> /// Bark history used to track the most recent bark, so the bark controller can go through /// the bark lines in a specified order. /// </param> public static void Bark(string conversationTitle, Transform speaker, Transform listener, BarkHistory barkHistory) { if (!hasInstance) { return; } instance.Bark(conversationTitle, speaker, listener, barkHistory); }
/// <summary> /// Causes a character to bark a line. A bark is a line spoken outside /// of a full conversation. It uses a simple gameplay bark UI instead of the dialogue UI. /// </summary> /// <param name='conversationTitle'> /// Title of the conversation that contains the bark lines. In this conversation, all /// dialogue entries linked from the first entry are considered bark lines. /// </param> /// <param name='speaker'> /// The character barking the line. /// </param> /// <param name='barkHistory'> /// Bark history used to track the most recent bark, so the bark controller can go through /// the bark lines in a specified order. /// </param> public static void Bark(string conversationTitle, Transform speaker, BarkHistory barkHistory) { Instance.Bark(conversationTitle, speaker, barkHistory); }
/// <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); } } }
void Awake() { barkHistory = new BarkHistory(barkOrder); sequencer = null; }
public BarkRequest(string conversation, BarkGroupMember member, Transform listener, BarkHistory barkHistory, float delayTime = -1) { this.member = member; this.listener = listener; this.conversation = conversation; this.barkHistory = barkHistory; this.barkText = null; this.sequence = null; this.barkUI = GetBarkUI(member); this.delayTime = GetDelayTime(member, delayTime); }
/// <summary> /// Barks with group awareness. /// </summary> /// <param name="conversation">Conversation to bark from.</param> /// <param name="member">Barker.</param> /// <param name="listener">Bark target.</param> /// <param name="barkHistory">Bark history.</param> /// <param name="delayTime">Omit/zero to use the member's random delay settings; if nonzero, use this delay time.</param> public void GroupBark(string conversation, BarkGroupMember member, Transform listener, BarkHistory barkHistory, float delayTime = 0) { if (member == null || !member.queueBarks) { DialogueManager.Bark(conversation, (member != null) ? member.transform : null, listener, barkHistory); } else { Enqueue(new BarkRequest(conversation, member, listener, barkHistory, delayTime)); } }
protected virtual void Awake() { barkHistory = new BarkHistory(barkOrder); sequencer = null; barkGroupMember = GetBarker().GetComponent <BarkGroupMember>(); }
/// <summary> /// Causes a character to bark a line. A bark is a line spoken outside /// of a full conversation. It uses a simple gameplay bark UI instead of the dialogue UI. /// </summary> /// <param name='conversationTitle'> /// Title of the conversation that contains the bark lines. In this conversation, all /// dialogue entries linked from the first entry are considered bark lines. /// </param> /// <param name='speaker'> /// The character barking the line. /// </param> /// <param name='barkHistory'> /// Bark history used to track the most recent bark, so the bark controller can go through /// the bark lines in a specified order. /// </param> public void Bark(string conversationTitle, Transform speaker, BarkHistory barkHistory) { Bark(conversationTitle, speaker, null, barkHistory); }
/// <summary> /// Causes a character to bark a line at another character. A bark is a line spoken outside /// of a full conversation. It uses a simple gameplay bark UI instead of the dialogue UI. /// </summary> /// <param name='conversationTitle'> /// Title of the conversation that contains the bark lines. In this conversation, all /// dialogue entries linked from the first entry are considered bark lines. /// </param> /// <param name='speaker'> /// The character barking the line. /// </param> /// <param name='listener'> /// The character being barked at. /// </param> /// <param name='barkHistory'> /// Bark history used to track the most recent bark, so the bark controller can go through /// the bark lines in a specified order. /// </param> public void Bark(string conversationTitle, Transform speaker, Transform listener, BarkHistory barkHistory) { CheckDebugLevel(); StartCoroutine(BarkController.Bark(conversationTitle, speaker, listener, barkHistory)); }