Beispiel #1
0
    private float PlayScheduled(InAudioNode startNode, InAudioNode currentNode, InAudioData audioData,
                                double playAtDSPTime, float offset, out float nodeVolume)
    {
        float length = 0;

        nodeVolume = 1;
        if (audioData._clip != null)
        {
            var clip = audioData._clip;
            length = clip.ExactLength();

            length -= offset;
            float lengthOffset = offset * clip.frequency;
            var   source       = Current.AudioSource;


            source.clip            = clip;
            nodeVolume             = RuntimeHelper.CalcVolume(startNode, currentNode);
            Current.OriginalVolume = nodeVolume;

            SetVolume(Current, audioParameters.Volume);

            source.spatialBlend = RuntimeHelper.CalcBlend(startNode, currentNode);
            source.pitch        = RuntimeHelper.CalcPitch(startNode, currentNode) * audioParameters.Pitch;
            source.rolloffMode  = RuntimeHelper.CalcAttentutation(startNode, currentNode, source);
            if (audioParameters.SetMixer)
            {
                source.outputAudioMixerGroup = audioParameters.AudioMixer;
            }
            else
            {
                source.outputAudioMixerGroup = currentNode.GetMixerGroup();
            }
            length            = RuntimeHelper.LengthFromPitch(length, source.pitch);
            Current.EndTime   = playAtDSPTime + length;
            Current.StartTime = playAtDSPTime;
            Current.UsedNode  = currentNode;

            source.panStereo    += audioParameters.StereoPan;
            source.spread        = _spread;
            source.spatialBlend *= audioParameters.SpatialBlend;
            source.timeSamples   = (int)(lengthOffset);
            source.PlayScheduled(playAtDSPTime);

            // SK: Koreographer integration
            var visor = Current.GetComponent <SonicBloom.Koreo.Players.AudioSourceVisor>();
            if (!visor)
            {
                visor = Current.gameObject.AddComponent <SonicBloom.Koreo.Players.AudioSourceVisor>();
            }
            visor.ScheduledPlayTime = playAtDSPTime;
            visor.ResyncTimings(0);
        }
        else
        {
            Debug.LogWarning("InAudio: Audio clip missing on audio node \"" + currentNode.Name + "\", id=" + currentNode._ID);
        }
        return(length);
    }