Ejemplo n.º 1
0
        /// <summary>
        /// This method allows you to slowly change to a new pitch.
        /// </summary>
        /// <param name="pitchAddition">The pitch to add to the current pitch.</param>
        /// <param name="glideTime">The time it will take to change to that pitch.</param>
        /// <param name="completionCallback">(Optional) - a method to execute when the pitch glide has completed.</param>
        public void GlideByPitch(float pitchAddition, float glideTime, System.Action completionCallback = null)
        {
            if (pitchAddition == 0)   // nothing to do
            {
                if (completionCallback != null)
                {
                    completionCallback();
                }
                return;
            }

            var targetPitch = VarAudio.pitch + pitchAddition;

            if (targetPitch < -3f)
            {
                targetPitch = -3f;
            }

            if (targetPitch > 3f)
            {
                targetPitch = 3f;
            }

            if (!VarAudio.clip.IsClipReadyToPlay())
            {
                if (ParentGroup.LoggingEnabledForGroup)
                {
                    MasterAudio.LogWarning("Cannot GlideToPitch Variation '" + name + "' because it is still loading.");
                }
                return;
            }

            if (glideTime <= MasterAudio.InnerLoopCheckInterval)
            {
                if (VarAudio.pitch != targetPitch)
                {
                    VarAudio.pitch = targetPitch; // time really short, just do it at once.
                }
                if (completionCallback != null)
                {
                    completionCallback();
                }
                return;
            }

            if (VariationUpdater != null)
            {
                VariationUpdater.GlidePitch(targetPitch, glideTime, completionCallback);
            }
        }