Ejemplo n.º 1
0
 public void DoAction(BarkAction action, Transform actor)
 {
     if (action != null) {
         Transform speaker = Tools.Select(action.speaker, this.transform);
         Transform listener = Tools.Select(action.listener, actor);
         DialogueManager.Bark(action.conversation, speaker, listener, barkHistory);
         sequencer = BarkController.LastSequencer;
     }
 }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
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 ((subtitle == null) || (subtitle.speakerInfo == null)) yield break;
     Transform speaker = subtitle.speakerInfo.transform;
     Transform listener = (subtitle.listenerInfo != null) ? subtitle.listenerInfo.transform : null;
     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, 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 (!(skipSequence || 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);
 }
Ejemplo n.º 4
0
 void Awake()
 {
     barkHistory = new BarkHistory(barkOrder);
     sequencer = null;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Barks if the condition is true.
 /// </summary>
 /// <param name="target">Target.</param>
 /// <param name="interactor">Interactor to test the condition against.</param>
 public void TryBark(Transform target, Transform interactor)
 {
     if (!tryingToBark) {
         tryingToBark = true;
         try {
             if ((condition == null) || condition.IsTrue(interactor)) {
                 if (string.IsNullOrEmpty(conversation)) {
                     if (DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Bark triggered on {1}, but conversation name is blank.", new System.Object[] { DialogueDebug.Prefix, name }), GetBarker());
                 } else if (DialogueManager.IsConversationActive && !allowDuringConversations) {
                     if (DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Bark triggered on {1}, but a conversation is already active.", new System.Object[] { DialogueDebug.Prefix, name }), GetBarker());
                 } else if (cacheBarkLines) {
                     BarkCachedLine(GetBarker(), target);
                 } else {
                     DialogueManager.Bark(conversation, GetBarker(), target, barkHistory);
                     sequencer = BarkController.LastSequencer;
                 }
                 DestroyIfOnce();
             }
         } finally {
             tryingToBark = false;
         }
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initialize a UI and sequencer with displaySettings.
 /// </summary>
 /// <param name='ui'>
 /// Dialogue UI.
 /// </param>
 /// <param name='sequencer'>
 /// Sequencer.
 /// </param>
 /// <param name='displaySettings'>
 /// Display settings to initiate the UI and sequencer with.
 /// </param>
 public void Initialize(IDialogueUI ui, Sequencer sequencer, DisplaySettings displaySettings, DialogueEntrySpokenDelegate dialogueEntrySpokenHandler)
 {
     this.ui = ui;
     this.sequencer = sequencer;
     this.settings = displaySettings;
     this.dialogueEntrySpokenHandler = dialogueEntrySpokenHandler;
     ui.Open ();
     sequencer.Open ();
     ui.SelectedResponseHandler += OnSelectedResponse;
     sequencer.FinishedSequenceHandler += OnFinishedSubtitle;
 }
 /// <summary>
 /// Stops a sequence.
 /// </summary>
 /// <param name='sequencer'>
 /// The sequencer playing the sequence.
 /// </param>
 public void StopSequence(Sequencer sequencer)
 {
     if (sequencer != null) sequencer.Close();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Stops a sequence.
 /// </summary>
 /// <param name='sequencer'>
 /// The sequencer playing the sequence.
 /// </param>
 public static void StopSequence(Sequencer sequencer)
 {
     Instance.StopSequence(sequencer);
 }