Beispiel #1
0
        private bool restoreOriginalClip = false; // Don't restore; could stop next entry's AudioWait that runs same frame.

        public IEnumerator Start()
        {
            string    audioClipName = GetParameter(0);
            Transform subject       = GetSubject(1);

            nextClipIndex = 2;
            if (DialogueDebug.logInfo)
            {
                Debug.Log(string.Format("{0}: Sequencer: AudioWait({1})", new System.Object[] { DialogueDebug.Prefix, GetParameters() }));
            }
            audioSource = SequencerTools.GetAudioSource(subject);
            if (audioSource == null)
            {
                if (DialogueDebug.logWarnings)
                {
                    Debug.LogWarning(string.Format("{0}: Sequencer: AudioWait() command: can't find or add AudioSource to {1}.", new System.Object[] { DialogueDebug.Prefix, subject.name }));
                }
                Stop();
            }
            else
            {
                originalClip = audioSource.clip;
                stopTime     = DialogueTime.time + 1; // Give time for yield return null.
                yield return(null);

                originalClip = audioSource.clip;
                TryAudioClip(audioClipName);
            }
        }
Beispiel #2
0
        public void Start()
        {
            string    audioClipName = GetParameter(0);
            Transform subject       = GetSubject(1);

            nextClipIndex = 2;
            if (DialogueDebug.LogInfo)
            {
                Debug.Log(string.Format("{0}: Sequencer: AudioWait({1})", new System.Object[] { DialogueDebug.Prefix, GetParameters() }));
            }
            audioSource = SequencerTools.GetAudioSource(subject);
            if (audioSource == null)
            {
                if (DialogueDebug.LogWarnings)
                {
                    Debug.LogWarning(string.Format("{0}: Sequencer: AudioWait() command: can't find or add AudioSource to {1}.", new System.Object[] { DialogueDebug.Prefix, subject.name }));
                }
            }
            else
            {
                if (Tools.ApproximatelyZero(audioSource.volume))
                {
                    audioSource.volume = 1f;
                }
                TryAudioClip(audioClipName);
            }
        }
        private bool _restoreOriginalClip = false;         // Don't restore original; could stop next entry's AudioWait that runs same frame.

        public IEnumerator Start()
        {
            string audioClipName = GetParameter(0);

            Transform subject = GetSubject(1);

            _nextClipIndex = 2;

            if (audioClipName == null || audioClipName.Length < 1)
            {
                if (DialogueDebug.LogWarnings)
                {
                    Debug.LogWarningFormat("{0}: Sequencer: AudioWaitOnce(): no audio clip name given", DialogueDebug.Prefix);
                }
                if (!this.hasNextClip())
                {
                    Stop();
                }
            }

            if (DialogueDebug.LogInfo)
            {
                Debug.LogFormat("{0}: Sequencer: AudioWaitOnce({1})", DialogueDebug.Prefix, GetParameters());
            }

            if (this.hasPlayedAlready(audioClipName))
            {
                if (DialogueDebug.LogInfo)
                {
                    Debug.LogFormat("{0}: Sequencer: AudioWaitOnce(): clip {1} already played, skipping", DialogueDebug.Prefix, audioClipName);
                    if (!this.hasNextClip())
                    {
                        Stop();
                    }
                }
            }

            _audioSource = SequencerTools.GetAudioSource(subject);
            if (_audioSource == null)
            {
                if (DialogueDebug.LogWarnings)
                {
                    Debug.LogWarningFormat("{0}: Sequencer: AudioWaitOnce(): can't find or add AudioSource to {1}.", DialogueDebug.Prefix, subject.name);
                }
                //  doesn't matter if we have other clips, no audio source means no play
                Stop();
            }
            else
            {
                _originalClip = _audioSource.clip;
                _stopTime     = DialogueTime.time + 1; // Give time for yield return null.
                yield return(null);

                _originalClip = _audioSource.clip;
                TryAudioClip(audioClipName);
            }
        }
Beispiel #4
0
        private Transform GetNamedTransform(string value)
        {
            Transform t = SequencerTools.GetSubject(value, Sequencer.Speaker, Sequencer.Listener);

            if (t == null && DialogueDebug.LogWarnings)
            {
                Debug.LogWarning(string.Format("{0}: Sequencer: BehaviorVariable({1}, {2}, {3}): couldn't find '{3}'", DialogueDebug.Prefix, GetParameter(0), GetParameter(1), GetParameter(2)));
            }
            return(t);
        }
Beispiel #5
0
        public void Start()
        {
            if (DialogueDebug.LogInfo)
            {
                Debug.Log(string.Format("{0}: Sequencer: AudioWWW({1}).", new System.Object[] { DialogueDebug.Prefix, string.Join(", ", Parameters) }));
            }
            // Create audio queue:
            for (int i = 0; i < (Parameters.Length - 1); i++)
            {
                string url = GetParameter(i);
                if (!string.IsNullOrEmpty(url))
                {
                    audioURLs.Enqueue(url);
                }
            }

            // Get subject or last clip:
            Transform subject   = null;
            string    lastParam = (Parameters.Length > 0) ? GetParameter(Parameters.Length - 1) : string.Empty;

            if (!string.IsNullOrEmpty(lastParam))
            {
                subject = GetSubject(Parameters.Length - 1, null);
                if (subject == null)
                {
                    subject = Sequencer.Speaker;
                    audioURLs.Enqueue(lastParam);
                }
            }

            if (audioURLs.Count == 0)
            {
                if (DialogueDebug.LogWarnings)
                {
                    Debug.LogWarning(string.Format("{0}: Sequencer: AudioWWW(): No URLs specified.", new System.Object[] { DialogueDebug.Prefix }));
                }
                Stop();
            }
            else
            {
                // Setup audio source:
                AudioSource audioSource = SequencerTools.GetAudioSource(subject);
                if (audioSource == null)
                {
                    if (DialogueDebug.LogWarnings)
                    {
                        Debug.LogWarning(string.Format("{0}: Sequencer: AudioWWW(): can't find or add AudioSource to {1}.", new System.Object[] { DialogueDebug.Prefix, Tools.GetGameObjectName(subject) }));
                    }
                    Stop();
                }
                else
                {
                    if (Tools.ApproximatelyZero(audioSource.volume))
                    {
                        audioSource.volume = 1f;
                    }
                    if (IsAudioMuted())
                    {
                        if (DialogueDebug.LogInfo)
                        {
                            Debug.Log(string.Format("{0}: Sequencer: AudioWWW({1}): audio is muted; waiting but not playing.", new System.Object[] { DialogueDebug.Prefix, string.Join(", ", Parameters) }));
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public void Start()
        {
            string audioClipName     = GetParameter(0);
            string animationClipName = GetParameter(1);

            finalClipName = GetParameter(2);
            subject       = GetSubject(3);
            anim          = (subject == null) ? null : subject.GetComponent <Animation>();
            animator      = (subject == null) ? null : subject.GetComponent <Animator>();
            AudioClip audioClip = (!string.IsNullOrEmpty(audioClipName)) ? (DialogueManager.LoadAsset(audioClipName) as AudioClip) : null;

            if ((anim == null) && (animator == null))
            {
                if (DialogueDebug.logWarnings)
                {
                    Debug.LogWarning(string.Format("{0}: Sequencer: Voice({1}, {2}, {3}, {4}) command: No Animator or Animation component found on {3}.", new System.Object[] { DialogueDebug.Prefix, audioClipName, animationClipName, finalClipName, (subject != null) ? subject.name : GetParameter(3) }));
                }
            }
            else if (audioClip == null)
            {
                if (DialogueDebug.logWarnings)
                {
                    Debug.LogWarning(string.Format("{0}: Sequencer: Voice({1}, {2}, {3}, {4}) command: Clip is null.", new System.Object[] { DialogueDebug.Prefix, audioClipName, animationClipName, finalClipName, subject.name }));
                }
            }
            else if (string.IsNullOrEmpty(animationClipName))
            {
                if (DialogueDebug.logWarnings)
                {
                    Debug.LogWarning(string.Format("{0}: Sequencer: Voice({1}, {2}, {3}, {4}) command: Animation name is blank.", new System.Object[] { DialogueDebug.Prefix, audioClipName, animationClipName, finalClipName, subject.name }));
                }
            }
            else
            {
                if (DialogueDebug.logInfo)
                {
                    Debug.Log(string.Format("{0}: Sequencer: Voice({1}, {2}, {3}, {4})", new System.Object[] { DialogueDebug.Prefix, audioClipName, animationClipName, finalClipName, Tools.GetObjectName(subject) }));
                }
                audioSource = SequencerTools.GetAudioSource(subject);
                if (audioSource == null)
                {
                    if (DialogueDebug.logWarnings)
                    {
                        Debug.LogWarning(string.Format("{0}: Sequencer: Voice() command: can't find or add AudioSource to {1}.", new System.Object[] { DialogueDebug.Prefix, subject.name }));
                    }
                }
                else
                {
                    if (IsAudioMuted())
                    {
                        if (DialogueDebug.logInfo)
                        {
                            Debug.Log(string.Format("{0}: Sequencer: Voice({1}, {2}, {3}, {4}): Audio is muted; not playing it.", new System.Object[] { DialogueDebug.Prefix, audioClipName, animationClipName, finalClipName, Tools.GetObjectName(subject) }));
                        }
                    }
                    else
                    {
                        audioSource.clip = audioClip;
                        audioSource.Play();
                    }
                    try
                    {
                        if (animator != null)
                        {
                            animator.CrossFade(animationClipName, 0.3f);
                            stopTime = DialogueTime.time + audioClip.length;
                        }
                        else
                        {
                            anim.CrossFade(animationClipName);
                            stopTime = DialogueTime.time + Mathf.Max(0.1f, anim[animationClipName].length - 0.3f);
                            if (audioClip.length > anim[animationClipName].length)
                            {
                                stopTime = DialogueTime.time + audioClip.length;
                            }
                        }
                    }
                    catch (System.Exception)
                    {
                        stopTime = 0;
                    }
                }
            }
        }
 /// <summary>
 /// Checks whether a Lua variable "Mute" is defined and <c>true</c>. If so, this
 /// indicates that audio should be muted.
 /// </summary>
 /// <returns><c>true</c> if audio is muted; otherwise, <c>false</c>.</returns>
 protected bool IsAudioMuted()
 {
     return(SequencerTools.IsAudioMuted());
 }
 /// <summary>
 /// Gets the i-th parameter (zero-based) as a specified type.
 /// </summary>
 /// <returns>
 /// The i-th parameter as type T, or the specified default value if <c>i</c> is out of
 /// range or the parameter can't be converted to type T.
 /// </returns>
 /// <param name='i'>
 /// The parameter index number (zero-based).
 /// </param>
 /// <param name='defaultValue'>
 /// The default value to return if <c>i</c> is out of range or the parameter can't be
 /// converted to type T.
 /// </param>
 /// <typeparam name='T'>
 /// The type to convert the parameter to.
 /// </typeparam>
 /// <example>
 /// // Get the second parameter as a float, defaulting to 5f:
 /// float duration = GetParameterAs<float>(1, 5f);
 /// </example>
 protected T GetParameterAs <T>(int i, T defaultValue)
 {
     return(SequencerTools.GetParameterAs <T>(Parameters, i, defaultValue));
 }
 /// <summary>
 /// Gets the i-th parameter (zero-based).
 /// </summary>
 /// <returns>
 /// The i-th parameter, or the specified default value if <c>i</c> is out of range.
 /// </returns>
 /// <param name='i'>
 /// The parameter index number (zero-based).
 /// </param>
 /// <param name='defaultValue'>
 /// The default value to return if <c>i</c> is out of range.
 /// </param>
 protected string GetParameter(int i, string defaultValue = null)
 {
     return(SequencerTools.GetParameter(Parameters, i, defaultValue));
 }
 /// <summary>
 /// Sequencer commands usually specify a subject to which the command applies (e.g., where
 /// to aim the camera). This utility function returns the specified subject.
 /// </summary>
 /// <returns>
 /// The transform of the specified subject, or null if the specifier names a game object
 /// that isn't in the scene.
 /// </returns>
 /// <param name='specifier'>
 /// <c>"speaker"</c>, <c>"listener"</c>, or the name of a game object in the scene.
 /// </param>
 /// <param name='defaultSubject'>
 /// Default subject (overrides speaker).
 /// </param>
 protected Transform GetSubject(string specifier, Transform defaultSubject = null)
 {
     return(SequencerTools.GetSubject(specifier, Sequencer.Speaker, Sequencer.Listener, defaultSubject));
 }
Beispiel #11
0
        public void Start()
        {
            // Get the values of the parameters:
            string angle = GetParameter(0, "Closeup");

            subject  = GetSubject(1);
            duration = GetParameterAsFloat(2, 0);

            // Get angle:
            bool isDefault = string.Equals(angle, "default");

            if (isDefault)
            {
                angle = SequencerTools.GetDefaultCameraAngle(subject);
            }
            isOriginal     = string.Equals(angle, "original");
            angleTransform = isOriginal
                                ? Camera.main.transform
                                : ((Sequencer.CameraAngles != null) ? Sequencer.CameraAngles.transform.Find(angle) : null);
            isLocalTransform = true;
            if (angleTransform == null)
            {
                isLocalTransform = false;
                GameObject go = GameObject.Find(angle);
                if (go != null)
                {
                    angleTransform = go.transform;
                }
            }

            // Log:
            if (DialogueDebug.LogInfo)
            {
                Debug.Log(string.Format("{0}: Sequencer: Camera({1}, {2}, {3}s)", new System.Object[] { DialogueDebug.Prefix, angle, Tools.GetGameObjectName(subject), duration }));
            }
            if ((angleTransform == null) && DialogueDebug.LogWarnings)
            {
                Debug.LogWarning(string.Format("{0}: Sequencer: Camera angle '{1}' wasn't found.", new System.Object[] { DialogueDebug.Prefix, angle }));
            }
            if ((subject == null) && DialogueDebug.LogWarnings)
            {
                Debug.LogWarning(string.Format("{0}: Sequencer: Camera subject '{1}' wasn't found.", new System.Object[] { DialogueDebug.Prefix, GetParameter(1) }));
            }

            // If we have a camera angle and subject, move the camera to it:
            Sequencer.TakeCameraControl();
            if (isOriginal || (angleTransform != null && subject != null))
            {
                cameraTransform = Sequencer.SequencerCameraTransform;
                if (isOriginal)
                {
                    targetRotation = Sequencer.OriginalCameraRotation;
                    targetPosition = Sequencer.OriginalCameraPosition;
                }
                else if (isLocalTransform)
                {
                    targetRotation = subject.rotation * angleTransform.localRotation;
                    targetPosition = subject.position + subject.rotation * angleTransform.localPosition;
                }
                else
                {
                    targetRotation = angleTransform.rotation;
                    targetPosition = angleTransform.position;
                }

                // If duration is above the cutoff, smoothly move camera toward camera angle:
                if (duration > SmoothMoveCutoff)
                {
                    startTime        = DialogueTime.time;
                    endTime          = startTime + duration;
                    originalRotation = cameraTransform.rotation;
                    originalPosition = cameraTransform.position;
                }
                else
                {
                    Stop();
                }
            }
            else
            {
                Stop();
            }
        }