// 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 actorTransform = (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 <StartConversationBehaviour> inputPlayable = (ScriptPlayable <StartConversationBehaviour>)playable.GetInput(i); StartConversationBehaviour input = inputPlayable.GetBehaviour(); if (Application.isPlaying) { if (input.jumpToSpecificEntry && input.entryID > 0) { DialogueManager.StartConversation(input.conversation, actorTransform, input.conversant, input.entryID); } else { DialogueManager.StartConversation(input.conversation, actorTransform, input.conversant); } } else { var message = "Conversation (" + DialogueActor.GetActorName(actorTransform) + "->" + DialogueActor.GetActorName(input.conversant) + "): [" + input.conversation + "] '" + input.GetEditorDialogueText() + "' (may vary)"; PreviewUI.ShowMessage(message, 2, 0); } } else if (inputWeight <= 0.001f && played.Contains(i)) { played.Remove(i); } } }
/// <summary> /// Shows the panel at the start of the conversation; called if it's configured to be visible at the start. /// </summary> /// <param name="portraitSprite">The image of the first actor who will use this panel.</param> /// <param name="portraitName">The name of the first actor who will use this panel.</param> /// <param name="dialogueActor">The actor's DialogueActor component, or null if none.</param> public virtual void OpenOnStartConversation(Sprite portraitSprite, string portraitName, DialogueActor dialogueActor) { Open(); SetUIElementsActive(true); Tools.SetGameObjectActive(this.portraitImage, portraitSprite != null); if (this.portraitImage != null) { this.portraitImage.sprite = portraitSprite; } if (this.portraitName != null) { this.portraitName.text = portraitName; } if (subtitleText.text != null) { subtitleText.text = string.Empty; } CheckDialogueActorAnimator(dialogueActor); }
/// <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); }
protected virtual string GetBarkerName() { return(DialogueActor.GetActorName(GetBarker((barkSource == BarkSource.Conversation) ? barkConversation : null))); }
/// <summary> /// Changes a dialogue actor's subtitle panel for the currently active conversation. /// </summary> public virtual void SetActorSubtitlePanelNumber(DialogueActor dialogueActor, SubtitlePanelNumber subtitlePanelNumber) { conversationUIElements.standardSubtitleControls.SetActorSubtitlePanelNumber(dialogueActor, subtitlePanelNumber); }
/// <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); } } } }
private StandardUISubtitlePanel GetActorTransformPanel(Transform speakerTransform, StandardUISubtitlePanel defaultPanel, out DialogueActor dialogueActor) { dialogueActor = null; if (speakerTransform == null) { return(defaultPanel); } if (m_dialogueActorCache.ContainsKey(speakerTransform)) { dialogueActor = m_dialogueActorCache[speakerTransform]; } else { dialogueActor = DialogueActor.GetDialogueActorComponent(speakerTransform); m_dialogueActorCache.Add(speakerTransform, dialogueActor); } if (m_actorPanelCache.ContainsKey(speakerTransform)) { return(m_actorPanelCache[speakerTransform]); } if (m_useBarkUIs.Contains(speakerTransform)) { return(null); } if (DialogueActorUsesBarkUI(dialogueActor)) { m_useBarkUIs.Add(speakerTransform); return(null); } else { var panel = GetDialogueActorPanel(dialogueActor); if (panel == null) { panel = defaultPanel; } m_actorPanelCache.Add(speakerTransform, panel); return(panel); } }
private bool DialogueActorUsesBarkUI(DialogueActor dialogueActor) { return(dialogueActor != null && dialogueActor.GetSubtitlePanelNumber() == SubtitlePanelNumber.UseBarkUI); }
public virtual StandardUIMenuPanel GetPanel(Subtitle lastSubtitle, Response[] responses) { // Find player's transform & DialogueActor: var playerTransform = (lastSubtitle != null && lastSubtitle.speakerInfo.isPlayer) ? lastSubtitle.speakerInfo.transform : (responses != null && responses.Length > 0) ? GetActorTransformFromID(responses[0].destinationEntry.ActorID) : (lastSubtitle != null && lastSubtitle.listenerInfo.isPlayer) ? lastSubtitle.listenerInfo.transform : DialogueManager.currentActor; if (playerTransform == null) { playerTransform = DialogueManager.currentActor; } var playerDialogueActor = DialogueActor.GetDialogueActorComponent(playerTransform); // Check NPC for non-default menu panel: var playerUsesDefaultMenuPanel = playerDialogueActor != null && playerDialogueActor.standardDialogueUISettings.menuPanelNumber == MenuPanelNumber.Default; var npcTransform = (lastSubtitle != null && lastSubtitle.speakerInfo.isNPC) ? lastSubtitle.speakerInfo.transform : (lastSubtitle != null) ? lastSubtitle.listenerInfo.transform : DialogueManager.currentConversant; if (npcTransform == null) { npcTransform = DialogueManager.currentConversant; } if (playerUsesDefaultMenuPanel && npcTransform != null && m_actorPanelCache.ContainsKey(npcTransform)) { // We've already cached a menu panel to use when responding to this NPC, so return it: return(m_actorPanelCache[npcTransform]); } var npcDialogueActor = DialogueActor.GetDialogueActorComponent(npcTransform); if (npcDialogueActor != null && (npcDialogueActor.standardDialogueUISettings.useMenuPanelFor == DialogueActor.UseMenuPanelFor.MeAndResponsesToMe || (npcDialogueActor.standardDialogueUISettings.menuPanelNumber != MenuPanelNumber.Default && playerUsesDefaultMenuPanel))) { // NPC's DialogueActor specifies a menu panel to use when responding to it, so cache and return it: var npcMenuPanel = GetDialogueActorPanel(npcDialogueActor); if (npcMenuPanel != null) { m_actorPanelCache[npcTransform] = npcMenuPanel; return(npcMenuPanel); } } if (playerTransform != null) { // If NPC doesn't specify a menu panel, check for an override by player's transform: if (m_actorPanelCache.ContainsKey(playerTransform)) { return(m_actorPanelCache[playerTransform]); } } else { // If no player transform, check for an override by player actor ID: var playerID = (lastSubtitle != null && lastSubtitle.speakerInfo.isPlayer) ? lastSubtitle.speakerInfo.id : (responses != null && responses.Length > 0) ? responses[0].destinationEntry.ActorID : -1; if (m_actorIdPanelCache.ContainsKey(playerID)) { return(m_actorIdPanelCache[playerID]); } } // Otherwise use player's menu panel: var panel = GetDialogueActorPanel(playerDialogueActor); if (panel == null) { panel = m_defaultPanel; } if (playerTransform != null) { m_actorPanelCache.Add(playerTransform, panel); } return(panel); }
public virtual void OpenOnStartConversation(Texture2D portraitTexture, string portraitName, DialogueActor dialogueActor) { OpenOnStartConversation(UITools.CreateSprite(portraitTexture), portraitName, dialogueActor); }
protected virtual StandardUIMenuPanel GetPanel(Subtitle lastSubtitle, Response[] responses) { // Find player's DialogueActor: var playerTransform = (lastSubtitle != null && lastSubtitle.speakerInfo.isPlayer) ? lastSubtitle.speakerInfo.transform : (responses != null && responses.Length > 0) ? GetActorTransformFromID(responses[0].destinationEntry.ActorID) : DialogueManager.currentActor; if (playerTransform == null) { playerTransform = DialogueManager.currentActor; } if (playerTransform == null) { var actorId = (lastSubtitle != null && lastSubtitle.speakerInfo.isPlayer) ? lastSubtitle.speakerInfo.id : -1; if (m_actorIdPanelCache.ContainsKey(actorId)) { return(m_actorIdPanelCache[actorId]); } else { return(m_defaultPanel); } } if (m_actorPanelCache.ContainsKey(playerTransform)) { return(m_actorPanelCache[playerTransform]); } var dialogueActor = DialogueActor.GetDialogueActorComponent(playerTransform); // Check NPC for non-default menu panel: var playerUsesDefaultMenuPanel = dialogueActor == null || dialogueActor.standardDialogueUISettings.menuPanelNumber == MenuPanelNumber.Default; var otherTransform = (lastSubtitle != null && lastSubtitle.speakerInfo.isNPC) ? lastSubtitle.speakerInfo.transform : DialogueManager.currentConversant; if (playerUsesDefaultMenuPanel && otherTransform != null && m_actorPanelCache.ContainsKey(otherTransform)) { return(m_actorPanelCache[otherTransform]); } var otherDialogueActor = DialogueActor.GetDialogueActorComponent(otherTransform); if (otherDialogueActor != null && (otherDialogueActor.standardDialogueUISettings.useMenuPanelFor == DialogueActor.UseMenuPanelFor.MeAndResponsesToMe || (otherDialogueActor.standardDialogueUISettings.menuPanelNumber != MenuPanelNumber.Default && playerUsesDefaultMenuPanel))) { if (otherTransform != null && m_actorPanelCache.ContainsKey(otherTransform)) { return(m_actorPanelCache[otherTransform]); } var otherPanel = GetDialogueActorPanel(otherDialogueActor); if (otherPanel != null) { return(otherPanel); } } // Otherwise use player's menu panel: var panel = GetDialogueActorPanel(dialogueActor); if (panel == null) { panel = m_defaultPanel; } m_actorPanelCache.Add(playerTransform, panel); return(panel); }
/// <summary> /// Shows the panel at the start of the conversation; called if it's configured to be visible at the start. /// </summary> /// <param name="portraitImage">The image of the first actor who will use this panel.</param> /// <param name="portraitName">The name of the first actor who will use this panel.</param> /// <param name="dialogueActor">The actor's DialogueActor component, or null if none.</param> public virtual void OpenOnStartConversation(Texture2D portraitImage, string portraitName, DialogueActor dialogueActor) { Open(); SetUIElementsActive(true); if (this.portraitImage != null) { this.portraitImage.sprite = UITools.CreateSprite(portraitImage); } if (this.portraitName != null) { this.portraitName.text = portraitName; } if (subtitleText.text != null) { subtitleText.text = string.Empty; } CheckDialogueActorAnimator(dialogueActor); }
private string GetBarkerName() { return(DialogueActor.GetActorName(GetBarker())); }
public static string GetInternalName(Transform t) { return(DialogueActor.GetPersistentDataName(t)); }
/// <summary> /// Changes a dialogue actor's menu panel for the currently active conversation. /// </summary> public virtual void SetActorMenuPanelNumber(DialogueActor dialogueActor, MenuPanelNumber menuPanelNumber) { conversationUIElements.standardMenuControls.SetActorMenuPanelNumber(dialogueActor, menuPanelNumber); }