コード例 #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 (audLocation == MasterAudio.AudioLocation.ResourceFile && !MasterAudio.Instance.resourceClipsPauseDoNotUnload)
        {
            Stop();
            return;
        }

        _audio.Pause();
        this.curFadeMode      = FadeMode.None;
        this.curDetectEndMode = DetectEndMode.None;         // necessary so that the clip can be unpaused.

        MaybeUnloadClip();
    }
コード例 #2
0
    /// <summary>
    /// This method is called automatically from MasterAudio.PlaySound and MasterAudio.PlaySound3D.
    /// </summary>
    /// <param name="maxVolume">If fade in time is not zero on this Variation, max volume is the fully faded in clip's target volume. Otherwise this is not used.</param>
    public void Play(float?pitch, float maxVolume, PlaySoundParams playParams = null)
    {
        SoundFinished     = null; // clear it out so subscribers don't have to clean up
        isWaitingForDelay = false;
        playSndParams     = playParams;

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

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

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

        // set fade mode
        this.curFadeMode = FadeMode.None;
        curDetectEndMode = DetectEndMode.DetectEnd;

        StopAllCoroutines();

        if (audLocation == MasterAudio.AudioLocation.Clip)
        {
            FinishSetupToPlay();
            return;
        }

        _maxVol = maxVolume;
        AudioResourceOptimizer.PopulateSourcesWithResourceClip(resourceFileName, this);

        if (audLocation == MasterAudio.AudioLocation.ResourceFile)
        {
            FinishSetupToPlay();
        }
    }
コード例 #3
0
    /// <summary>
    /// This method allows you to stop the audio being played by this Variation.
    /// </summary>
    public void Stop(bool stopEndDetection = false)
    {
        if (stopEndDetection || isWaitingForDelay)
        {
            curDetectEndMode = DetectEndMode.None; // turn off the chain loop endless repeat
        }

        objectToFollow      = null;
        objectToTriggerFrom = null;
        ParentGroup.RemoveActiveAudioSourceId(this);

        _audio.Stop();

        playSndParams = null;

        if (SoundFinished != null)
        {
            SoundFinished(); // parameters aren't used
        }

        MaybeUnloadClip();
    }
コード例 #4
0
    /// <summary>
    /// This method is called automatically from MasterAudio.PlaySound and MasterAudio.PlaySound3D.
    /// </summary>
    /// <param name="maxVolume">If fade in time is not zero on this Variation, max volume is the fully faded in clip's target volume. Otherwise this is not used.</param>
    public void Play(float?pitch, float maxVolume, PlaySoundParams playParams = null)
    {
        SoundFinished     = null; // clear it out so subscribers don't have to clean up
        isWaitingForDelay = false;
        playSndParams     = playParams;

        // compute pitch
        if (pitch.HasValue)
        {
            _audio.pitch = pitch.Value;
        }
        else
        {
            var randPitch = 0f;

            if (randomPitch != 0f)
            {
                randPitch = UnityEngine.Random.Range(-randomPitch, randomPitch);
            }
            _audio.pitch = OriginalPitch + randPitch;
        }

        // set fade mode
        this.curFadeMode = FadeMode.None;
        curDetectEndMode = DetectEndMode.DetectEnd;

        StopAllCoroutines();

        if (audLocation == MasterAudio.AudioLocation.Clip)
        {
            FinishSetupToPlay(maxVolume);
            return;
        }

        StartCoroutine(LoadResourceFileAsync(resourceFileName, maxVolume));
    }
コード例 #5
0
    /// <summary>
    /// This method allows you to stop the audio being played by this Variation.
    /// </summary>
    public void Stop(bool stopEndDetection = false)
    {
        if (stopEndDetection || isWaitingForDelay)
        {
            curDetectEndMode = DetectEndMode.None; // turn off the chain loop endless repeat
        }

        objectToFollow      = null;
        objectToTriggerFrom = null;
        ParentGroup.RemoveActiveAudioSourceId(InstanceId);

        VarAudio.Stop();
        VarAudio.time = 0f;

        playSndParams = null;

        if (SoundFinished != null)
        {
            SoundFinished();      // parameters aren't used
            SoundFinished = null; // clear it out so subscribers don't have to clean up
        }

        MaybeUnloadClip();
    }
コード例 #6
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="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, 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;
                }
            }

            SoundFinished      = null; // clear it out so subscribers don't have to clean up
            _isWaitingForDelay = false;

            SetPlaySoundParams(gameObjectName, volPercent, targetVol, targetPitch, sourceTrans, attach, delayTime, 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
            // in case it was changed at runtime.
            SetSpatialBlend();
#endif

            // set fade mode
            curFadeMode      = FadeMode.None;
            curDetectEndMode = DetectEndMode.DetectEnd;
            _maxVol          = maxVolume;

            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;
            }
        }
コード例 #7
0
    /// <summary>
    /// This method allows you to stop the audio being played by this Variation. 
    /// </summary>
    public void Stop(bool stopEndDetection = false)
    {
        if (stopEndDetection || isWaitingForDelay)
        {
            curDetectEndMode = DetectEndMode.None; // turn off the chain loop endless repeat
        }
		
		objectToFollow = null;	
        objectToTriggerFrom = null;
		ParentGroup.RemoveActiveAudioSourceId(InstanceId);
		
        VarAudio.Stop();
		VarAudio.time = 0f;
		
        playSndParams = null;

        if (SoundFinished != null)
        {
            SoundFinished(); // parameters aren't used
			SoundFinished = null; // clear it out so subscribers don't have to clean up
		}
		
		if (_updater != null) {
			GameObject.Destroy(_updater);
			_updater = null;
		}		
		
        MaybeUnloadClip();
    }
コード例 #8
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 (audLocation == MasterAudio.AudioLocation.ResourceFile && !MasterAudio.Instance.resourceClipsPauseDoNotUnload)
        {
            Stop();
            return;
        }

        VarAudio.Pause();
        this.curFadeMode = FadeMode.None;
		this.curDetectEndMode = DetectEndMode.None; // necessary so that the clip can be unpaused.
		
        MaybeUnloadClip();
    }
コード例 #9
0
    /// <summary>
    /// This method is called automatically from MasterAudio.PlaySound and MasterAudio.PlaySound3D. 
    /// </summary>
    /// <param name="maxVolume">If fade in time is not zero on this Variation, max volume is the fully faded in clip's target volume. Otherwise this is not used.</param>
    public void Play(float? pitch, float maxVolume, PlaySoundParams playParams = null)
    {
        SoundFinished = null; // clear it out so subscribers don't have to clean up
        isWaitingForDelay = false;
		playSndParams = playParams;

        // compute pitch
        if (pitch.HasValue) {
            VarAudio.pitch = pitch.Value;
        } else if (useRandomPitch) {
            var randPitch = UnityEngine.Random.Range(randomPitchMin, randomPitchMax);
            
			switch (randomPitchMode) {
				case RandomPitchMode.AddToClipPitch:
					randPitch += OriginalPitch;
					break;
			}
			
			VarAudio.pitch = randPitch;
        } else { // non random pitch
			VarAudio.pitch = OriginalPitch;
		}

        // set fade mode
        this.curFadeMode = FadeMode.None;
        curDetectEndMode = DetectEndMode.DetectEnd;
		_maxVol = maxVolume;

        StopAllCoroutines();
		
        if (audLocation == MasterAudio.AudioLocation.Clip) {
			FinishSetupToPlay();
			return;
		}
		
		AudioResourceOptimizer.PopulateSourcesWithResourceClip(resourceFileName, this);
		
		if (audLocation == MasterAudio.AudioLocation.ResourceFile) {
			FinishSetupToPlay();
		}
    }
コード例 #10
0
    public void Play(float? pitch, float maxVolume, string gameObjectName, float volPercent, float targetVol, float? targetPitch, Transform sourceTrans, bool attach, float delayTime, bool isChaining, bool isSingleSubscribedPlay)
    {
        SoundFinished = null; // clear it out so subscribers don't have to clean up
        isWaitingForDelay = false;

        playSndParam.soundType = gameObjectName;
        playSndParam.volumePercentage = volPercent;
        playSndParam.groupCalcVolume = targetVol;
        playSndParam.pitch = targetPitch;
        playSndParam.sourceTrans = sourceTrans;
        playSndParam.attachToSource = attach;
        playSndParam.delaySoundTime = delayTime;
        playSndParam.isChainLoop = isChaining;
        playSndParam.isSingleSubscribedPlay = isSingleSubscribedPlay;
        playSndParam.isPlaying = true;

        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 = UnityEngine.Random.Range(randomPitchMin, randomPitchMax);

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

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

        // set fade mode
        this.curFadeMode = FadeMode.None;
        curDetectEndMode = DetectEndMode.DetectEnd;
        _maxVol = maxVolume;

        if (audLocation == MasterAudio.AudioLocation.Clip) {
            FinishSetupToPlay();
            return;
        }

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

            FinishSetupToPlay();
        }
    }
コード例 #11
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
            }
        }
コード例 #12
0
    /// <summary>
    /// This method allows you to stop the audio being played by this Variation. 
    /// </summary>
    public void Stop(bool stopEndDetection = false)
    {
        if (stopEndDetection || isWaitingForDelay)
        {
            curDetectEndMode = DetectEndMode.None; // turn off the chain loop endless repeat
        }

        ParentGroup.RemoveActiveAudioSourceId(this);

        _audio.Stop();

        playSndParams = null;

        if (SoundFinished != null)
        {
            SoundFinished(); // parameters aren't used
        }

        MaybeUnloadClip();
    }
コード例 #13
0
    /// <summary>
    /// This method is called automatically from MasterAudio.PlaySound and MasterAudio.PlaySound3D. 
    /// </summary>
    /// <param name="maxVolume">If fade in time is not zero on this Variation, max volume is the fully faded in clip's target volume. Otherwise this is not used.</param>
    public void Play(float? pitch, float maxVolume, PlaySoundParams playParams = null)
    {
        SoundFinished = null; // clear it out so subscribers don't have to clean up
        isWaitingForDelay = false;
        playSndParams = playParams;

        // compute pitch
        if (pitch.HasValue)
        {
            _audio.pitch = pitch.Value;
        }
        else
        {
            var randPitch = 0f;

            if (randomPitch != 0f)
            {
                randPitch = UnityEngine.Random.Range(-randomPitch, randomPitch);
            }
            _audio.pitch = OriginalPitch + randPitch;
        }

        // set fade mode
        this.curFadeMode = FadeMode.None;
        curDetectEndMode = DetectEndMode.DetectEnd;

        if (audLocation == MasterAudio.AudioLocation.ResourceFile)
        {
            AudioResourceOptimizer.PopulateSourcesWithResourceClip(resourceFileName);
        }

        StopAllCoroutines();
        timesLocationUpdated = 0;

        if (!_audio.isPlaying && _audio.time > 0f)
        {
            // paused. Do nothing except Play
        }
        else if (useFades && (fadeInTime > 0f || fadeOutTime > 0f))
        {
            fadeMaxVolume = maxVolume;
            _audio.volume = 0f;
            StartCoroutine(FadeInOut());
        }

        if (playSndParams != null && playSndParams.isChainLoop)
        {
            _audio.loop = false;
        }

        ParentGroup.AddActiveAudioSourceId(this);

        StartCoroutine(DetectSoundFinished(playParams.delaySoundTime));

        attachToSource = false;

        bool useClipAgePriority = MasterAudio.Instance.prioritizeOnDistance && (MasterAudio.Instance.useClipAgePriority || ParentGroup.useClipAgePriority);
        if (playParams.attachToSource || useClipAgePriority) {
            attachToSource = playParams.attachToSource;
            StartCoroutine(FollowSoundMaker());
        }
    }
コード例 #14
0
        /*! \cond PRIVATE */
        public void Play(float? pitch, float maxVolume, string gameObjectName, float volPercent, float targetVol,
            float? targetPitch, Transform sourceTrans, bool attach, float delayTime, bool isChaining,
            bool isSingleSubscribedPlay)
        {
            if (!MasterAudio.IsWarming && audLocation == MasterAudio.AudioLocation.FileOnInternet) {
                switch (internetFileLoadStatus) {
                    case MasterAudio.InternetFileLoadStatus.Loading:
                        if (MasterAudio.Instance.LogSounds) {
                            MasterAudio.LogWarning("Cannot play Variation '" + name +
                                                   "' because its Internet file has not been downloaded yet.");
                        }
                        return;
                    case MasterAudio.InternetFileLoadStatus.Failed:
                        if (MasterAudio.Instance.LogSounds) {
                            MasterAudio.LogWarning("Cannot play Variation '" + name +
                                                   "' because its Internet file failed downloading.");
                        }
                        return;
                }
            }

            SoundFinished = null; // clear it out so subscribers don't have to clean up
            _isWaitingForDelay = false;

            _playSndParam.SoundType = gameObjectName;
            _playSndParam.VolumePercentage = volPercent;
            _playSndParam.GroupCalcVolume = targetVol;
            _playSndParam.Pitch = targetPitch;
            _playSndParam.SourceTrans = sourceTrans;
            _playSndParam.AttachToSource = attach;
            _playSndParam.DelaySoundTime = delayTime;
            _playSndParam.IsChainLoop = isChaining ||
                                        ParentGroup.curVariationMode == MasterAudioGroup.VariationMode.LoopedChain;
            _playSndParam.IsSingleSubscribedPlay = isSingleSubscribedPlay;
            _playSndParam.IsPlaying = true;

            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
            // in case it was changed at runtime.
            SetSpatialBlend();
            #endif

            // set fade mode
            curFadeMode = FadeMode.None;
            curDetectEndMode = DetectEndMode.DetectEnd;
            _maxVol = maxVolume;

            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;
            }
        }