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;
     }
 }
 /// <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));
     }
 }
Esempio n. 3
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
                 {
                     if (barkGroupMember != null)
                     {
                         barkGroupMember.GroupBark(conversation, target, barkHistory);
                     }
                     else
                     {
                         DialogueManager.Bark(conversation, GetBarker(), target, barkHistory);
                     }
                     sequencer = BarkController.LastSequencer;
                 }
                 DestroyIfOnce();
             }
         }
         finally
         {
             tryingToBark = false;
         }
     }
 }
Esempio n. 4
0
        protected virtual void DoBarkAction(Transform actor)
        {
            switch (barkSource)
            {
            case BarkSource.Conversation:
                if (string.IsNullOrEmpty(barkConversation))
                {
                    return;
                }
                if (DialogueManager.isConversationActive && !allowBarksDuringConversations)
                {
                    if (DialogueDebug.logWarnings)
                    {
                        Debug.LogWarning("Dialogue System: Bark triggered on " + name + ", but a conversation is already active.", GetBarker(barkConversation));
                    }
                }
                else if (cacheBarkLines)
                {
                    BarkCachedLine(GetBarker(barkConversation), Tools.Select(barkTarget, actor));
                }
                else
                {
                    DialogueManager.Bark(barkConversation, GetBarker(barkConversation), Tools.Select(barkTarget, actor), barkHistory);
                    sequencer = BarkController.LastSequencer;
                }
                break;

            case BarkSource.Text:
                if (string.IsNullOrEmpty(barkText))
                {
                    return;
                }
                if (DialogueManager.isConversationActive && !allowBarksDuringConversations)
                {
                    if (DialogueDebug.logWarnings)
                    {
                        Debug.LogWarning("Dialogue System: Bark triggered on " + name + ", but a conversation is already active.", GetBarker(null));
                    }
                }
                else
                {
                    DialogueManager.BarkString(barkText, GetBarker(null), Tools.Select(barkTarget, actor), barkTextSequence);
                    sequencer = BarkController.LastSequencer;
                }
                break;
            }
        }
        private void Update()
        {
            // Check each group's queue:
            var enumerator = queues.GetEnumerator(); // Enumerates manually to avoid garbage.

            while (enumerator.MoveNext())
            {
                var queue = enumerator.Current.Value;
                if (queue.Count == 0)
                {
                    continue;
                }
                var barkRequest = queue.Peek();
                if (!barkRequest.isPlaying)
                {
                    // If request at front of queue isn't playing yet, update time left:
                    barkRequest.delayTime -= Time.deltaTime;
                    if (barkRequest.delayTime <= 0)
                    {
                        // If it's now time, play the bark:
                        if (barkRequest.member == null || barkRequest.barkUI == null || (string.IsNullOrEmpty(barkRequest.conversation) && string.IsNullOrEmpty(barkRequest.barkText)))
                        {
                            queue.Dequeue();
                        }
                        else if (!string.IsNullOrEmpty(barkRequest.conversation))
                        {
                            DialogueManager.Bark(barkRequest.conversation, barkRequest.member.transform, barkRequest.listener, barkRequest.barkHistory);
                        }
                        else
                        {
                            DialogueManager.BarkString(barkRequest.barkText, barkRequest.member.transform, barkRequest.listener, barkRequest.sequence);
                        }
                        barkRequest.isPlaying = true;
                        barkRequest.delayTime = 0.5f; // Wait a little for bark to set up before checking if it's done playing.
                    }
                }
                else
                {
                    barkRequest.delayTime -= Time.deltaTime;
                    if (barkRequest.delayTime <= 0 && !barkRequest.barkUI.isPlaying)
                    {
                        // If request at front of queue is playing but bark UI is done playing, dequeue:
                        queue.Dequeue();
                    }
                }
            }
        }
        // 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;

            if (!trackBinding)
            {
                return;
            }

            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 <BarkBehaviour> inputPlayable = (ScriptPlayable <BarkBehaviour>)playable.GetInput(i);
                    BarkBehaviour input = inputPlayable.GetBehaviour();
                    if (Application.isPlaying)
                    {
                        if (input.useConversation)
                        {
                            DialogueManager.Bark(input.conversation, trackBinding.transform, input.listener);
                        }
                        else
                        {
                            DialogueManager.BarkString(input.text, trackBinding.transform, input.listener);
                        }
                    }
                    else
                    {
                        var message = DialogueActor.GetActorName(trackBinding.transform) + " bark: " + input.GetEditorBarkText();
                        if (input.useConversation)
                        {
                            message += " (may vary)";
                        }
                        PreviewUI.ShowMessage(message, 2, 1);
                    }
                }
                else if (inputWeight <= 0.001f && played.Contains(i))
                {
                    played.Remove(i);
                }
            }
        }