Ejemplo n.º 1
0
        /// <summary>
        /// This method allows you to pause the audio being played by this Variation. This is automatically called by MasterAudio.PauseSoundGroup and MasterAudio.PauseBus.
        /// </summary>
        public void Pause()
        {
            if (!MasterAudio.Instance.resourceClipsPauseDoNotUnload)
            {
                switch (audLocation)
                {
                case MasterAudio.AudioLocation.ResourceFile:
                    Stop();
                    return;

                case MasterAudio.AudioLocation.Clip:
                    if (!AudioUtil.AudioClipWillPreload(VarAudio.clip))
                    {
                        Stop();
                        return;
                    }
                    break;
                }
            }

            _isPaused = true;
            VarAudio.Pause();
            if (VariationUpdater.enabled)
            {
                VariationUpdater.Pause();
            }
            curFadeMode  = FadeMode.None;
            curPitchMode = PitchMode.None;
        }
        //тангаж (pitch)
        public void OnPitch(PitchMode _mode, float _speedMod = 1.0f)
        {
            var direction = Vector3.zero;

            switch (_mode)
            {
            case PitchMode.ToDown:
                direction = Vector3.right;
                break;

            case PitchMode.ToUp:
                direction = -Vector3.right;
                break;
            }

            AddCommand(new ManeuverCommandData(ManeuverCommand.OnPitch, ManeuverType.Rotate, direction * config.data.pitchSpeed * _speedMod));
        }
Ejemplo n.º 3
0
        /*! \cond PRIVATE */
        /// <summary>
        /// Never call this method. Used internally.
        /// </summary>
        /// <param name="pitch">Pitch.</param>
        /// <param name="maxVolume">Max volume.</param>
        /// <param name="gameObjectName">Game object name.</param>
        /// <param name="volPercent">Vol percent.</param>
        /// <param name="targetVol">Target vol.</param>
        /// <param name="targetPitch">Target pitch.</param>
        /// <param name="sourceTrans">Source trans.</param>
        /// <param name="attach">If set to <c>true</c> attach.</param>
        /// <param name="delayTime">Delay time.</param>
        /// <param name="timeToSchedulePlay"><b>Optional</b> - used to pass in the DSP time to play the sound. Play now if null.</param>
        /// <param name="isChaining">If set to <c>true</c> is chaining.</param>
        /// <param name="isSingleSubscribedPlay">If set to <c>true</c> is single subscribed play.</param>
        public void Play(float?pitch, float maxVolume, string gameObjectName, float volPercent, float targetVol,
                         float?targetPitch, Transform sourceTrans, bool attach, float delayTime,
                         double?timeToSchedulePlay, bool isChaining, bool isSingleSubscribedPlay)
        {
            if (!MasterAudio.IsWarming && audLocation == MasterAudio.AudioLocation.FileOnInternet)
            {
                switch (internetFileLoadStatus)
                {
                case MasterAudio.InternetFileLoadStatus.Loading:
                    if (ParentGroup.LoggingEnabledForGroup)
                    {
                        MasterAudio.LogWarning("Cannot play Variation '" + name +
                                               "' because its Internet file has not been downloaded yet.");
                    }
                    return;

                case MasterAudio.InternetFileLoadStatus.Failed:
                    if (ParentGroup.LoggingEnabledForGroup)
                    {
                        MasterAudio.LogWarning("Cannot play Variation '" + name +
                                               "' because its Internet file failed downloading.");
                    }
                    return;
                }
            }

            MaybeCleanupFinishedDelegate();
            _hasStartedEndLinkedGroups = false;
            _isPaused = false;

            SetPlaySoundParams(gameObjectName, volPercent, targetVol, targetPitch, sourceTrans, attach, delayTime, timeToSchedulePlay, isChaining, isSingleSubscribedPlay);

            SetPriority(); // reset it back to normal priority in case you're playing 2D this time.

            if (MasterAudio.HasAsyncResourceLoaderFeature() && ShouldLoadAsync)
            {
                StopAllCoroutines(); // The only Coroutine right now requires pro version and Unity 4.5.3
            }

            // compute pitch
            if (pitch.HasValue)
            {
                VarAudio.pitch = pitch.Value;
            }
            else if (useRandomPitch)
            {
                var randPitch = Random.Range(randomPitchMin, randomPitchMax);

                switch (randomPitchMode)
                {
                case RandomPitchMode.AddToClipPitch:
                    randPitch += OriginalPitch;
                    break;
                }

                VarAudio.pitch = randPitch;
            }
            else
            {
                // non random pitch
                VarAudio.pitch = OriginalPitch;
            }

#if UNITY_5 || UNITY_2017_1_OR_NEWER
            // in case it was changed at runtime.
            SetSpatialBlend();
#endif

            // set fade mode
            curFadeMode      = FadeMode.None;
            curPitchMode     = PitchMode.None;
            curDetectEndMode = DetectEndMode.DetectEnd;
            _maxVol          = maxVolume;
            if (maxCustomLoops == minCustomLoops)
            {
                _maxLoops = minCustomLoops;
            }
            else
            {
                _maxLoops = Random.Range(minCustomLoops, maxCustomLoops + 1);
            }

            switch (audLocation)
            {
            case MasterAudio.AudioLocation.Clip:
                FinishSetupToPlay();
                return;

            case MasterAudio.AudioLocation.ResourceFile:
                if (MasterAudio.HasAsyncResourceLoaderFeature() && ShouldLoadAsync)
                {
                    StartCoroutine(AudioResourceOptimizer.PopulateSourcesWithResourceClipAsync(ResFileName, this,
                                                                                               FinishSetupToPlay, ResourceFailedToLoad));
                }
                else
                {
                    if (!AudioResourceOptimizer.PopulateSourcesWithResourceClip(ResFileName, this))
                    {
                        return;     // audio file not found!
                    }

                    FinishSetupToPlay();
                }
                return;

            case MasterAudio.AudioLocation.FileOnInternet:
                FinishSetupToPlay();
                return;
            }
        }
Ejemplo n.º 4
0
        /*! \cond PRIVATE */
        /// <summary>
        /// Never call this method. Used internally.
        /// </summary>
        /// <param name="pitch">Pitch.</param>
        /// <param name="maxVolume">Max volume.</param>
        /// <param name="gameObjectName">Game object name.</param>
        /// <param name="volPercent">Vol percent.</param>
        /// <param name="targetVol">Target vol.</param>
        /// <param name="targetPitch">Target pitch.</param>
        /// <param name="sourceTrans">Source trans.</param>
        /// <param name="attach">If set to <c>true</c> attach.</param>
        /// <param name="delayTime">Delay time.</param>
        /// <param name="timeToSchedulePlay"><b>Optional</b> - used to pass in the DSP time to play the sound. Play now if null.</param>
        /// <param name="isChaining">If set to <c>true</c> is chaining.</param>
        /// <param name="isSingleSubscribedPlay">If set to <c>true</c> is single subscribed play.</param>
        public void Play(float?pitch, float maxVolume, string gameObjectName, float volPercent, float targetVol,
                         float?targetPitch, Transform sourceTrans, bool attach, float delayTime,
                         double?timeToSchedulePlay, bool isChaining, bool isSingleSubscribedPlay)
        {
            LoadStatus       = MasterAudio.VariationLoadStatus.None;
            _isStopRequested = false;
            _isWarmingPlay   = MasterAudio.IsWarming;

            MaybeCleanupFinishedDelegate();
            _hasStartedEndLinkedGroups = false;
            _isPaused = false;

            SetPlaySoundParams(gameObjectName, volPercent, targetVol, targetPitch, sourceTrans, attach, delayTime, timeToSchedulePlay, isChaining, isSingleSubscribedPlay);

            SetPriority(); // reset it back to normal priority in case you're playing 2D this time.

            // compute pitch
            if (pitch.HasValue)
            {
                VarAudio.pitch = pitch.Value;
            }
            else if (useRandomPitch)
            {
                var randPitch = Random.Range(randomPitchMin, randomPitchMax);

                switch (randomPitchMode)
                {
                case RandomPitchMode.AddToClipPitch:
                    randPitch += OriginalPitch;
                    break;
                }

                VarAudio.pitch = randPitch;
            }
            else
            {
                // non random pitch
                VarAudio.pitch = OriginalPitch;
            }

            // in case it was changed at runtime.
            SetSpatialBlend();

            // set fade mode
            curFadeMode      = FadeMode.None;
            curPitchMode     = PitchMode.None;
            curDetectEndMode = DetectEndMode.DetectEnd;
            _maxVol          = maxVolume;
            if (maxCustomLoops == minCustomLoops)
            {
                _maxLoops = minCustomLoops;
            }
            else
            {
                _maxLoops = Random.Range(minCustomLoops, maxCustomLoops + 1);
            }

            LoadStatus = MasterAudio.VariationLoadStatus.Loading;

            switch (audLocation)
            {
            case MasterAudio.AudioLocation.Clip:
                FinishSetupToPlay();
                return;

            case MasterAudio.AudioLocation.ResourceFile:
                if (_loadResourceFileCoroutine != null)
                {
                    StopCoroutine(_loadResourceFileCoroutine);
                }

                _loadResourceFileCoroutine = StartCoroutine(AudioResourceOptimizer.PopulateSourcesWithResourceClipAsync(ResFileName, this,
                                                                                                                        FinishSetupToPlay, ResourceFailedToLoad));
                return;

#if ADDRESSABLES_ENABLED
            case MasterAudio.AudioLocation.Addressable:
                if (_loadAddressableCoroutine != null)
                {
                    StopCoroutine(_loadAddressableCoroutine);
                }

                _loadAddressableCoroutine = StartCoroutine(AudioAddressableOptimizer.PopulateSourceWithAddressableClipAsync(audioClipAddressable,
                                                                                                                            this, ParentGroup.AddressableUnusedSecondsLifespan, FinishSetupToPlay, ResourceFailedToLoad));
                return;
#endif
            }
        }