Exemplo n.º 1
0
    // ReSharper disable once UnusedMember.Local
    private void OnTriggerExit(Collider other)
    {
        if (RuntimeFollowingTransform == null)
        {
            return;
        }

        if (other == null || other.name != AmbientUtil.ListenerFollowerName)
        {
            return;             // abort if not colliding with Listener.
        }

        _isInsideTrigger = false;
        _hasPlayedSound  = false;

        switch (_exitMode)
        {
        case MasterAudio.AmbientSoundExitMode.StopSound:
            MasterAudio.StopSoundGroupOfTransform(RuntimeFollowingTransform, _soundType);
            break;

        case MasterAudio.AmbientSoundExitMode.FadeSound:
            MasterAudio.FadeOutSoundGroupOfTransform(RuntimeFollowingTransform, _soundType, _exitFadeTime);
            break;
        }

        playingVariation = null;
    }
Exemplo n.º 2
0
    private void PerformTriggerExit()
    {
        _isInsideTrigger = false;
        _hasPlayedSound  = false;

        var grp = MasterAudio.GrabGroup(_soundType, false);

        if (grp == null)   // might be destroyed! Proceeding will log spam.
        {
            return;
        }

        switch (_exitMode)
        {
        case MasterAudio.AmbientSoundExitMode.StopSound:
            MasterAudio.StopSoundGroupOfTransform(RuntimeFollowingTransform, _soundType);
            break;

        case MasterAudio.AmbientSoundExitMode.FadeSound:
            MasterAudio.FadeOutSoundGroupOfTransform(RuntimeFollowingTransform, _soundType, _exitFadeTime);
            break;
        }

        fadingVariation  = playingVariation;
        playingVariation = null;

        //StopFollowing();
    }
Exemplo n.º 3
0
    void OnMouseUp()
    {
        if (this.useMouseUpSound)
        {
            PlaySounds(mouseUpSound, EventType.OnMouseUp);
        }

        if (this.useMouseDragSound)
        {
            switch (mouseUpSound.mouseDragStopMode)
            {
            case PreviousSoundStopMode.Stop:
                // stop the drag sound
                if (mouseDragResult != null && (mouseDragResult.SoundPlayed || mouseDragResult.SoundScheduled))
                {
                    mouseDragResult.ActingVariation.Stop(true);
                }
                break;

            case PreviousSoundStopMode.FadeOut:
                // stop the drag sound
                if (mouseDragResult != null && (mouseDragResult.SoundPlayed || mouseDragResult.SoundScheduled))
                {
                    mouseDragResult.ActingVariation.FadeToVolume(0f, mouseUpSound.mouseDragFadeOutTime);
                }
                break;
            }

            mouseDragResult = null;
        }

        mouseDragSoundPlayed = false;         // can play drag sound again next time
    }
Exemplo n.º 4
0
    private void PlaySound()
    {
        if (_willFollowSource)
        {
            if (_positionAtClosestColliderPoint)
            {
                playingVariation = MasterAudio.PlaySound3DFollowTransform(_soundType, RuntimeFollowingTransform);
            }
            else
            {
                MasterAudio.PlaySound3DFollowTransformAndForget(_soundType, RuntimeFollowingTransform);
            }
        }
        else
        {
            if (_positionAtClosestColliderPoint)
            {
                playingVariation = MasterAudio.PlaySound3DAtTransform(_soundType, RuntimeFollowingTransform);
            }
            else
            {
                MasterAudio.PlaySound3DAtTransformAndForget(_soundType, RuntimeFollowingTransform);
            }
        }

        _hasPlayedSound = true;
    }
Exemplo n.º 5
0
    private void PlaySound()
    {
        var hasSpecificVariation = !string.IsNullOrEmpty(_variationName);

        if (_willFollowSource)
        {
            if (_positionAtClosestColliderPoint)
            {
                if (hasSpecificVariation)
                {
                    playingVariation = MasterAudio.PlaySound3DFollowTransform(_soundType, RuntimeFollowingTransform, 1f, 1f, 0f, _variationName);
                }
                else
                {
                    playingVariation = MasterAudio.PlaySound3DFollowTransform(_soundType, RuntimeFollowingTransform);
                }
            }
            else
            {
                if (hasSpecificVariation)
                {
                    MasterAudio.PlaySound3DFollowTransformAndForget(_soundType, RuntimeFollowingTransform, 1f, 1f, 0f, _variationName);
                }
                else
                {
                    MasterAudio.PlaySound3DFollowTransformAndForget(_soundType, RuntimeFollowingTransform);
                }
            }
        }
        else
        {
            if (_positionAtClosestColliderPoint)
            {
                if (hasSpecificVariation)
                {
                    playingVariation = MasterAudio.PlaySound3DAtTransform(_soundType, RuntimeFollowingTransform, 1f, 1f, 0f, _variationName);
                }
                else
                {
                    playingVariation = MasterAudio.PlaySound3DAtTransform(_soundType, RuntimeFollowingTransform);
                }
            }
            else
            {
                if (hasSpecificVariation)
                {
                    MasterAudio.PlaySound3DAtTransformAndForget(_soundType, RuntimeFollowingTransform, 1f, 1f, 0f, _variationName);
                }
                else
                {
                    MasterAudio.PlaySound3DAtTransformAndForget(_soundType, RuntimeFollowingTransform);
                }
            }
        }

        _hasPlayedSound = true;
    }
Exemplo n.º 6
0
    void OnEnable()
    {
        mouseDragResult = null;
        RegisterReceiver();

        if (this.useEnableSound)
        {
            PlaySounds(enableSound, EventType.OnEnable);
        }
    }
Exemplo n.º 7
0
    // ReSharper disable once UnusedMember.Local
    private void OnTriggerExit(Collider other)
    {
        if (RuntimeFollowingTransform == null)
        {
            return;
        }

        if (other == null || other.name != AmbientUtil.ListenerFollowerName)
        {
            return;             // abort if not colliding with Listener.
        }

        _isInsideTrigger = false;
        _hasPlayedSound  = false;
        MasterAudio.StopSoundGroupOfTransform(RuntimeFollowingTransform, _soundType);
        playingVariation = null;
    }
    private void PlaySound(AudioEvent aEvent)
    {
        if (disableSounds)
        {
            return;
        }

        float  volume = aEvent.volume;
        string sType  = aEvent.soundType;
        float? pitch  = aEvent.pitch;

        if (!aEvent.useFixedPitch)
        {
            pitch = null;
        }

        PlaySoundResult soundPlayed = null;

        switch (soundSpawnMode)
        {
        case MasterAudio.SoundSpawnLocationMode.CallerLocation:
            soundPlayed = MasterAudio.PlaySound3DAtTransform(sType, this.trans, volume, pitch);
            break;

        case MasterAudio.SoundSpawnLocationMode.AttachToCaller:
            soundPlayed = MasterAudio.PlaySound3DFollowTransform(sType, this.trans, volume, pitch);
            break;

        case MasterAudio.SoundSpawnLocationMode.MasterAudioLocation:
            soundPlayed = MasterAudio.PlaySound(sType, volume);
            break;
        }

        if (soundPlayed == null || !soundPlayed.SoundPlayed)
        {
            return;
        }

        if (aEvent.emitParticles)
        {
            MasterAudio.TriggerParticleEmission(this.trans, aEvent.particleCountToEmit);
        }
    }
Exemplo n.º 9
0
    private PlaySoundResult PlaySound(AudioEvent aEvent, EventType eType, bool isFirstTry = true)
    {
        if (disableSounds || MasterAudio.AppIsShuttingDown) {
            return null;
        }

        float volume = aEvent.volume;
        string sType = aEvent.soundType;
        float? pitch = aEvent.pitch;
        if (!aEvent.useFixedPitch) {
            pitch = null;
        }

        PlaySoundResult soundPlayed = null;

        var soundSpawnModeToUse = soundSpawnMode;

         	if (aEvent == disableSound || aEvent == despawnedSound) {
            soundSpawnModeToUse = MasterAudio.SoundSpawnLocationMode.CallerLocation;
        }

        switch (aEvent.currentSoundFunctionType) {
            case MasterAudio.EventSoundFunctionType.PlaySound:
                string variationName = null;
                if (aEvent.variationType == VariationType.PlaySpecific) {
                    variationName = aEvent.variationName;
                }

                if (eType == EventType.OnStart && isFirstTry && !MasterAudio.SoundGroupExists(sType)) {
                   // don't try to play sound yet.
                } else {
                    switch (soundSpawnModeToUse)
                    {
                        case MasterAudio.SoundSpawnLocationMode.CallerLocation:
                            soundPlayed = MasterAudio.PlaySound3DAtTransform(sType, this.trans, volume, pitch, aEvent.delaySound, variationName);
                            break;
                        case MasterAudio.SoundSpawnLocationMode.AttachToCaller:
                            soundPlayed = MasterAudio.PlaySound3DFollowTransform(sType, this.trans, volume, pitch, aEvent.delaySound, variationName);
                            break;
                        case MasterAudio.SoundSpawnLocationMode.MasterAudioLocation:
                            soundPlayed = MasterAudio.PlaySound(sType, volume, pitch, aEvent.delaySound, variationName);
                            break;
                    }
                }

                if (soundPlayed == null || !soundPlayed.SoundPlayed) {
                    if (eType == EventType.OnStart && isFirstTry) {
                        // race condition met. So try to play it a few more times.
                        StartCoroutine(TryPlayStartSound(aEvent));
                    }
                    return soundPlayed;
                }
                break;
            case MasterAudio.EventSoundFunctionType.PlaylistControl:
                soundPlayed = new PlaySoundResult() {
                    ActingVariation = null,
                    SoundPlayed = true,
                    SoundScheduled = false
                };

                switch (aEvent.currentPlaylistCommand) {
                    case MasterAudio.PlaylistCommand.None:
                        soundPlayed.SoundPlayed = false;
                        break;
                    case MasterAudio.PlaylistCommand.ChangePlaylist:
                        if (string.IsNullOrEmpty(aEvent.playlistName)) {
                            Debug.Log("You have not specified a Playlist name for Event Sounds on '" + this.trans.name + "'.");
                            soundPlayed.SoundPlayed = false;
                        } else {
                            if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) {
                                // don't play
                            } else {
                                MasterAudio.ChangePlaylistByName(aEvent.playlistControllerName, aEvent.playlistName, aEvent.startPlaylist);
                            }
                        }

                        break;
                    case MasterAudio.PlaylistCommand.FadeToVolume:
                        if (aEvent.allPlaylistControllersForGroupCmd) {
                            MasterAudio.FadeAllPlaylistsToVolume(aEvent.fadeVolume, aEvent.fadeTime);
                        } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) {
                            // don't play
                        } else {
                            MasterAudio.FadePlaylistToVolume(aEvent.playlistControllerName, aEvent.fadeVolume, aEvent.fadeTime);
                        }
                        break;
                    case MasterAudio.PlaylistCommand.PlayClip:
                        if (string.IsNullOrEmpty(aEvent.clipName)) {
                            Debug.Log("You have not specified a clip name for Event Sounds on '" + this.trans.name + "'.");
                            soundPlayed.SoundPlayed = false;
                        } else {
                            if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) {
                                // don't play
                            } else {
                                MasterAudio.TriggerPlaylistClip(aEvent.playlistControllerName, aEvent.clipName);
                            }
                        }

                        break;
                    case MasterAudio.PlaylistCommand.PlayRandomSong:
                        if (aEvent.allPlaylistControllersForGroupCmd) {
                            MasterAudio.TriggerRandomClipAllPlaylists();
                        } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) {
                            // don't play
                        } else {
                            MasterAudio.TriggerRandomPlaylistClip(aEvent.playlistControllerName);
                        }
                        break;
                    case MasterAudio.PlaylistCommand.PlayNextSong:
                        if (aEvent.allPlaylistControllersForGroupCmd) {
                            MasterAudio.TriggerNextClipAllPlaylists();
                        } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) {
                            // don't play
                        } else {
                            MasterAudio.TriggerNextPlaylistClip(aEvent.playlistControllerName);
                        }
                        break;
                    case MasterAudio.PlaylistCommand.Pause:
                        if (aEvent.allPlaylistControllersForGroupCmd) {
                            MasterAudio.PauseAllPlaylists();
                        } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) {
                            // don't play
                        } else {
                            MasterAudio.PausePlaylist(aEvent.playlistControllerName);
                        }
                        break;
                    case MasterAudio.PlaylistCommand.Stop:
                        if (aEvent.allPlaylistControllersForGroupCmd) {
                            MasterAudio.StopAllPlaylists();
                        } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) {
                            // don't play
                        } else {
                            MasterAudio.StopPlaylist(aEvent.playlistControllerName);
                        }
                        break;
                    case MasterAudio.PlaylistCommand.Resume:
                        if (aEvent.allPlaylistControllersForGroupCmd) {
                            MasterAudio.ResumeAllPlaylists();
                        } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) {
                            // don't play
                        } else {
                            MasterAudio.ResumePlaylist(aEvent.playlistControllerName);
                        }
                        break;
                }
                break;
            case MasterAudio.EventSoundFunctionType.GroupControl:
                soundPlayed = new PlaySoundResult() {
                    ActingVariation = null,
                    SoundPlayed = true,
                    SoundScheduled = false
                };

                var soundTypesForCmd = new List<string>();
                if (!aEvent.allSoundTypesForGroupCmd) {
                    soundTypesForCmd.Add(aEvent.soundType);
                } else {
                    soundTypesForCmd.AddRange(MasterAudio.RuntimeSoundGroupNames);
                }

                for (var i = 0 ; i < soundTypesForCmd.Count; i++) {
                    var soundType = soundTypesForCmd[i];

                    switch (aEvent.currentSoundGroupCommand) {
                        case MasterAudio.SoundGroupCommand.None:
                            soundPlayed.SoundPlayed = false;
                            break;
                        case MasterAudio.SoundGroupCommand.FadeToVolume:
                            MasterAudio.FadeSoundGroupToVolume(soundType, aEvent.fadeVolume, aEvent.fadeTime);
                            break;
                        case MasterAudio.SoundGroupCommand.FadeOutAllOfSound:
                            MasterAudio.FadeOutAllOfSound(soundType, aEvent.fadeTime);
                            break;
                        case MasterAudio.SoundGroupCommand.Mute:
                            MasterAudio.MuteGroup(soundType);
                            break;
                        case MasterAudio.SoundGroupCommand.Pause:
                            MasterAudio.PauseSoundGroup(soundType);
                            break;
                        case MasterAudio.SoundGroupCommand.Solo:
                            MasterAudio.SoloGroup(soundType);
                            break;
                        case MasterAudio.SoundGroupCommand.StopAllOfSound:
                            MasterAudio.StopAllOfSound(soundType);
                            break;
                        case MasterAudio.SoundGroupCommand.Unmute:
                            MasterAudio.UnmuteGroup(soundType);
                            break;
                        case MasterAudio.SoundGroupCommand.Unpause:
                            MasterAudio.UnpauseSoundGroup(soundType);
                            break;
                        case MasterAudio.SoundGroupCommand.Unsolo:
                            MasterAudio.UnsoloGroup(soundType);
                            break;
                    }
                }

                break;
            case MasterAudio.EventSoundFunctionType.BusControl:
                soundPlayed = new PlaySoundResult() {
                    ActingVariation = null,
                    SoundPlayed = true,
                    SoundScheduled = false
                };

                var busesForCmd = new List<string>();
                if (!aEvent.allSoundTypesForBusCmd) {
                    busesForCmd.Add(aEvent.busName);
                } else {
                    busesForCmd.AddRange(MasterAudio.RuntimeBusNames);
                }

                for (var i = 0; i < busesForCmd.Count; i++) {
                    var busName = busesForCmd[i];

                    switch (aEvent.currentBusCommand) {
                        case MasterAudio.BusCommand.None:
                            soundPlayed.SoundPlayed = false;
                            break;
                        case MasterAudio.BusCommand.FadeToVolume:
                            MasterAudio.FadeBusToVolume(busName, aEvent.fadeVolume, aEvent.fadeTime);
                            break;
                        case MasterAudio.BusCommand.Pause:
                            MasterAudio.PauseBus(busName);
                            break;
                        case MasterAudio.BusCommand.Stop:
                            MasterAudio.StopBus(busName);
                            break;
                        case MasterAudio.BusCommand.Unpause:
                            MasterAudio.UnpauseBus(busName);
                            break;
                        case MasterAudio.BusCommand.Mute:
                            MasterAudio.MuteBus(busName);
                            break;
                        case MasterAudio.BusCommand.Unmute:
                            MasterAudio.UnmuteBus(busName);
                            break;
                        case MasterAudio.BusCommand.Solo:
                            MasterAudio.SoloBus(busName);
                            break;
                        case MasterAudio.BusCommand.Unsolo:
                            MasterAudio.UnsoloBus(busName);
                            break;
                    }
                }

                break;
            case MasterAudio.EventSoundFunctionType.CustomEventControl:
                soundPlayed = new PlaySoundResult() {
                    ActingVariation = null,
                    SoundPlayed = false,
                    SoundScheduled = false
                };

                if (eType == EventType.UserDefinedEvent) {
                    Debug.LogError("Custom Event Receivers cannot fire events. Occured in Transform '" + this.name + "'.");
                    break;
                }
                switch (aEvent.currentCustomEventCommand) {
                    case MasterAudio.CustomEventCommand.FireEvent:
                        MasterAudio.FireCustomEvent(aEvent.customEventName);
                        break;
                }
                break;
        }

        if (aEvent.emitParticles && soundPlayed != null && (soundPlayed.SoundPlayed || soundPlayed.SoundScheduled)) {
            MasterAudio.TriggerParticleEmission(this.trans, aEvent.particleCountToEmit);
        }

        return soundPlayed;
    }
Exemplo n.º 10
0
    void OnMouseUp()
    {
        if (this.useMouseUpSound) {
            PlaySounds(mouseUpSound, EventType.OnMouseUp);
        }

        if (this.useMouseDragSound) {
            switch (mouseUpSound.mouseDragStopMode) {
                case PreviousSoundStopMode.Stop:
                    // stop the drag sound
                    if (mouseDragResult != null && (mouseDragResult.SoundPlayed || mouseDragResult.SoundScheduled)) {
                        mouseDragResult.ActingVariation.Stop(true);
                    }
                    break;
                case PreviousSoundStopMode.FadeOut:
                    // stop the drag sound
                    if (mouseDragResult != null && (mouseDragResult.SoundPlayed || mouseDragResult.SoundScheduled)) {
                        mouseDragResult.ActingVariation.FadeToVolume(0f, mouseUpSound.mouseDragFadeOutTime);
                    }
                    break;
            }

            mouseDragResult = null;
        }

        mouseDragSoundPlayed = false; // can play drag sound again next time
    }
Exemplo n.º 11
0
    void OnEnable()
    {
        mouseDragResult = null;
        RegisterReceiver();

        if (this.useEnableSound) {
            PlaySounds(enableSound, EventType.OnEnable);
        }
    }
Exemplo n.º 12
0
    private PlaySoundResult PlaySound(AudioEvent aEvent, EventType eType, bool isFirstTry = true)
    {
        if (disableSounds || MasterAudio.AppIsShuttingDown)
        {
            return(null);
        }

        float  volume = aEvent.volume;
        string sType  = aEvent.soundType;
        float? pitch  = aEvent.pitch;

        if (!aEvent.useFixedPitch)
        {
            pitch = null;
        }

        PlaySoundResult soundPlayed = null;

        var soundSpawnModeToUse = soundSpawnMode;

        if (aEvent == disableSound || aEvent == despawnedSound)
        {
            soundSpawnModeToUse = MasterAudio.SoundSpawnLocationMode.CallerLocation;
        }

        switch (aEvent.currentSoundFunctionType)
        {
        case MasterAudio.EventSoundFunctionType.PlaySound:
            string variationName = null;
            if (aEvent.variationType == VariationType.PlaySpecific)
            {
                variationName = aEvent.variationName;
            }

            if (eType == EventType.OnStart && isFirstTry && !MasterAudio.SoundGroupExists(sType))
            {
                // don't try to play sound yet.
            }
            else
            {
                switch (soundSpawnModeToUse)
                {
                case MasterAudio.SoundSpawnLocationMode.CallerLocation:
                    soundPlayed = MasterAudio.PlaySound3DAtTransform(sType, this.trans, volume, pitch, aEvent.delaySound, variationName);
                    break;

                case MasterAudio.SoundSpawnLocationMode.AttachToCaller:
                    soundPlayed = MasterAudio.PlaySound3DFollowTransform(sType, this.trans, volume, pitch, aEvent.delaySound, variationName);
                    break;

                case MasterAudio.SoundSpawnLocationMode.MasterAudioLocation:
                    soundPlayed = MasterAudio.PlaySound(sType, volume, pitch, aEvent.delaySound, variationName);
                    break;
                }
            }

            if (soundPlayed == null || !soundPlayed.SoundPlayed)
            {
                if (eType == EventType.OnStart && isFirstTry)
                {
                    // race condition met. So try to play it a few more times.
                    StartCoroutine(TryPlayStartSound(aEvent));
                }
                return(soundPlayed);
            }
            break;

        case MasterAudio.EventSoundFunctionType.PlaylistControl:
            soundPlayed = new PlaySoundResult()
            {
                ActingVariation = null,
                SoundPlayed     = true,
                SoundScheduled  = false
            };

            if (string.IsNullOrEmpty(aEvent.playlistControllerName))
            {
                aEvent.playlistControllerName = MasterAudio.ONLY_PLAYLIST_CONTROLLER_NAME;
            }

            switch (aEvent.currentPlaylistCommand)
            {
            case MasterAudio.PlaylistCommand.None:
                soundPlayed.SoundPlayed = false;
                break;

            case MasterAudio.PlaylistCommand.ChangePlaylist:
                if (string.IsNullOrEmpty(aEvent.playlistName))
                {
                    Debug.Log("You have not specified a Playlist name for Event Sounds on '" + this.trans.name + "'.");
                    soundPlayed.SoundPlayed = false;
                }
                else
                {
                    if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME)
                    {
                        // don't play
                    }
                    else
                    {
                        MasterAudio.ChangePlaylistByName(aEvent.playlistControllerName, aEvent.playlistName, aEvent.startPlaylist);
                    }
                }

                break;

            case MasterAudio.PlaylistCommand.FadeToVolume:
                if (aEvent.allPlaylistControllersForGroupCmd)
                {
                    MasterAudio.FadeAllPlaylistsToVolume(aEvent.fadeVolume, aEvent.fadeTime);
                }
                else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME)
                {
                    // don't play
                }
                else
                {
                    MasterAudio.FadePlaylistToVolume(aEvent.playlistControllerName, aEvent.fadeVolume, aEvent.fadeTime);
                }
                break;

            case MasterAudio.PlaylistCommand.PlayClip:
                if (string.IsNullOrEmpty(aEvent.clipName))
                {
                    Debug.Log("You have not specified a clip name for Event Sounds on '" + this.trans.name + "'.");
                    soundPlayed.SoundPlayed = false;
                }
                else
                {
                    if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME)
                    {
                        // don't play
                    }
                    else
                    {
                        MasterAudio.TriggerPlaylistClip(aEvent.playlistControllerName, aEvent.clipName);
                    }
                }

                break;

            case MasterAudio.PlaylistCommand.PlayRandomSong:
                if (aEvent.allPlaylistControllersForGroupCmd)
                {
                    MasterAudio.TriggerRandomClipAllPlaylists();
                }
                else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME)
                {
                    // don't play
                }
                else
                {
                    MasterAudio.TriggerRandomPlaylistClip(aEvent.playlistControllerName);
                }
                break;

            case MasterAudio.PlaylistCommand.PlayNextSong:
                if (aEvent.allPlaylistControllersForGroupCmd)
                {
                    MasterAudio.TriggerNextClipAllPlaylists();
                }
                else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME)
                {
                    // don't play
                }
                else
                {
                    MasterAudio.TriggerNextPlaylistClip(aEvent.playlistControllerName);
                }
                break;

            case MasterAudio.PlaylistCommand.Pause:
                if (aEvent.allPlaylistControllersForGroupCmd)
                {
                    MasterAudio.PauseAllPlaylists();
                }
                else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME)
                {
                    // don't play
                }
                else
                {
                    MasterAudio.PausePlaylist(aEvent.playlistControllerName);
                }
                break;

            case MasterAudio.PlaylistCommand.Stop:
                if (aEvent.allPlaylistControllersForGroupCmd)
                {
                    MasterAudio.StopAllPlaylists();
                }
                else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME)
                {
                    // don't play
                }
                else
                {
                    MasterAudio.StopPlaylist(aEvent.playlistControllerName);
                }
                break;

            case MasterAudio.PlaylistCommand.Resume:
                if (aEvent.allPlaylistControllersForGroupCmd)
                {
                    MasterAudio.ResumeAllPlaylists();
                }
                else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME)
                {
                    // don't play
                }
                else
                {
                    MasterAudio.ResumePlaylist(aEvent.playlistControllerName);
                }
                break;
            }
            break;

        case MasterAudio.EventSoundFunctionType.GroupControl:
            soundPlayed = new PlaySoundResult()
            {
                ActingVariation = null,
                SoundPlayed     = true,
                SoundScheduled  = false
            };

            var soundTypesForCmd = new List <string>();
            if (!aEvent.allSoundTypesForGroupCmd)
            {
                soundTypesForCmd.Add(aEvent.soundType);
            }
            else
            {
                soundTypesForCmd.AddRange(MasterAudio.RuntimeSoundGroupNames);
            }

            for (var i = 0; i < soundTypesForCmd.Count; i++)
            {
                var soundType = soundTypesForCmd[i];

                switch (aEvent.currentSoundGroupCommand)
                {
                case MasterAudio.SoundGroupCommand.None:
                    soundPlayed.SoundPlayed = false;
                    break;

                case MasterAudio.SoundGroupCommand.FadeToVolume:
                    MasterAudio.FadeSoundGroupToVolume(soundType, aEvent.fadeVolume, aEvent.fadeTime);
                    break;

                case MasterAudio.SoundGroupCommand.FadeOutAllOfSound:
                    MasterAudio.FadeOutAllOfSound(soundType, aEvent.fadeTime);
                    break;

                case MasterAudio.SoundGroupCommand.Mute:
                    MasterAudio.MuteGroup(soundType);
                    break;

                case MasterAudio.SoundGroupCommand.Pause:
                    MasterAudio.PauseSoundGroup(soundType);
                    break;

                case MasterAudio.SoundGroupCommand.Solo:
                    MasterAudio.SoloGroup(soundType);
                    break;

                case MasterAudio.SoundGroupCommand.StopAllOfSound:
                    MasterAudio.StopAllOfSound(soundType);
                    break;

                case MasterAudio.SoundGroupCommand.Unmute:
                    MasterAudio.UnmuteGroup(soundType);
                    break;

                case MasterAudio.SoundGroupCommand.Unpause:
                    MasterAudio.UnpauseSoundGroup(soundType);
                    break;

                case MasterAudio.SoundGroupCommand.Unsolo:
                    MasterAudio.UnsoloGroup(soundType);
                    break;
                }
            }

            break;

        case MasterAudio.EventSoundFunctionType.BusControl:
            soundPlayed = new PlaySoundResult()
            {
                ActingVariation = null,
                SoundPlayed     = true,
                SoundScheduled  = false
            };

            var busesForCmd = new List <string>();
            if (!aEvent.allSoundTypesForBusCmd)
            {
                busesForCmd.Add(aEvent.busName);
            }
            else
            {
                busesForCmd.AddRange(MasterAudio.RuntimeBusNames);
            }

            for (var i = 0; i < busesForCmd.Count; i++)
            {
                var busName = busesForCmd[i];

                switch (aEvent.currentBusCommand)
                {
                case MasterAudio.BusCommand.None:
                    soundPlayed.SoundPlayed = false;
                    break;

                case MasterAudio.BusCommand.FadeToVolume:
                    MasterAudio.FadeBusToVolume(busName, aEvent.fadeVolume, aEvent.fadeTime);
                    break;

                case MasterAudio.BusCommand.Pause:
                    MasterAudio.PauseBus(busName);
                    break;

                case MasterAudio.BusCommand.Stop:
                    MasterAudio.StopBus(busName);
                    break;

                case MasterAudio.BusCommand.Unpause:
                    MasterAudio.UnpauseBus(busName);
                    break;

                case MasterAudio.BusCommand.Mute:
                    MasterAudio.MuteBus(busName);
                    break;

                case MasterAudio.BusCommand.Unmute:
                    MasterAudio.UnmuteBus(busName);
                    break;

                case MasterAudio.BusCommand.Solo:
                    MasterAudio.SoloBus(busName);
                    break;

                case MasterAudio.BusCommand.Unsolo:
                    MasterAudio.UnsoloBus(busName);
                    break;
                }
            }

            break;

        case MasterAudio.EventSoundFunctionType.CustomEventControl:
            soundPlayed = new PlaySoundResult()
            {
                ActingVariation = null,
                SoundPlayed     = false,
                SoundScheduled  = false
            };

            if (eType == EventType.UserDefinedEvent)
            {
                Debug.LogError("Custom Event Receivers cannot fire events. Occured in Transform '" + this.name + "'.");
                break;
            }
            switch (aEvent.currentCustomEventCommand)
            {
            case MasterAudio.CustomEventCommand.FireEvent:
                MasterAudio.FireCustomEvent(aEvent.customEventName);
                break;
            }
            break;
        }

        if (aEvent.emitParticles && soundPlayed != null && (soundPlayed.SoundPlayed || soundPlayed.SoundScheduled))
        {
            MasterAudio.TriggerParticleEmission(this.trans, aEvent.particleCountToEmit);
        }

        return(soundPlayed);
    }
Exemplo n.º 13
0
    private static PlaySoundResult PlaySoundIfAvailable(string soundGroupName,
            AudioInfo info,
            Vector3 sourcePosition,
            float volumePercentage,
            ref bool forgetSoundPlayed,
            float? pitch = null,
            AudioGroupInfo audioGroup = null,
            Transform sourceTrans = null,
            bool attachToSource = false,
            float delaySoundTime = 0f,
            bool useVector3 = false,
            bool makePlaySoundResult = false,
			bool isChaining = false,
			bool isSingleSubscribedPlay = false)
    {
        if (info.source == null)
        {
            // this avoids false errors when stopping the game (from became "invisible" event callers)
            return null;
        }

        MasterAudioGroup maGroup = audioGroup._group;

        if (maGroup.curVariationMode == MasterAudioGroup.VariationMode.Normal && info.source.audio.isPlaying)
        {
            var playedPercentage = AudioUtil.GetAudioPlayedPercentage(info.source);
            var retriggerPercent = maGroup.retriggerPercentage;

            if (playedPercentage < retriggerPercent)
            {
                return null; // wait for this to stop playing or play further.
            }
        }

        info.variation.Stop();
        info.variation.ObjectToFollow = null;

        if (useVector3)
        {
            info.source.transform.position = sourcePosition;
            if (MasterAudio.Instance.prioritizeOnDistance)
            {
                AudioPrioritizer.Set3dPriority(info.source);
            }
        }
        else if (sourceTrans != null)
        {
            if (attachToSource)
            {
                info.variation.ObjectToFollow = sourceTrans;
            }
            else
            {
                info.source.transform.position = sourceTrans.position;
                info.variation.ObjectToTriggerFrom = sourceTrans;
            }

            if (MasterAudio.Instance.prioritizeOnDistance)
            {
                AudioPrioritizer.Set3dPriority(info.source);
            }
        }
        else
        {
            // "2d manner" - from Master Audio location
            if (MasterAudio.Instance.prioritizeOnDistance)
            {
                AudioPrioritizer.Set2dSoundPriority(info.source);
            }
            info.source.transform.localPosition = Vector3.zero; // put it back in MA prefab position after being detached.
        }

        var groupVolume = maGroup.groupMasterVolume;
        var busVolume = GetBusVolume(maGroup);

        float calcVolume = info.originalVolume * groupVolume * busVolume * MasterAudio.Instance.masterAudioVolume;

        // set volume to percentage.
        float volume = calcVolume * volumePercentage;
        var targetVolume = volume;

        var randomVol = 0f;
        if (info.variation.useRandomVolume) {
            // random volume
            randomVol = UnityEngine.Random.Range(info.variation.randomVolumeMin, info.variation.randomVolumeMax);

            switch (info.variation.randomVolumeMode) {
                case SoundGroupVariation.RandomVolumeMode.AddToClipVolume:
                    targetVolume += randomVol;
                    break;
                case SoundGroupVariation.RandomVolumeMode.IgnoreClipVolume:
                    targetVolume = randomVol;
                    break;
            }
        }

        info.source.audio.volume = targetVolume;

        // save these for on the fly adjustments afterward
        info.lastPercentageVolume = volumePercentage;
        info.lastRandomVolume = randomVol;

        bool isActive = false;

        #if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
        isActive = info.source.audio.gameObject.active;
        #else
            isActive = info.source.audio.gameObject.activeInHierarchy;
        #endif

        if (!isActive)
        {
            return null;
        }

        PlaySoundResult result = null;

        if (makePlaySoundResult)
        {
            result = new PlaySoundResult();
            result.ActingVariation = info.variation;

            if (delaySoundTime > 0f)
            {
                result.SoundScheduled = true;
            }
            else
            {
                result.SoundPlayed = true;
            }
        }
        else
        {
            forgetSoundPlayed = true;
        }

        var playSoundParams = new SoundGroupVariation.PlaySoundParams(maGroup.name,
              volumePercentage,
              targetVolume,
              pitch,
              sourceTrans,
              attachToSource,
              delaySoundTime,
              maGroup.curVariationMode == MasterAudioGroup.VariationMode.LoopedChain,
              isSingleSubscribedPlay);

        if (playSoundParams.isChainLoop && !isChaining) {
            maGroup.ChainLoopCount = 0;
        }

        if (playSoundParams.isChainLoop)
        {
            // make sure there isn't 2 going, ever
            MasterAudio.StopAllOfSound(playSoundParams.soundType);
        }

        info.variation.Play(pitch, targetVolume, playSoundParams);

        return result;
    }
Exemplo n.º 14
0
    private void PlaySound()
    {
        var hasSpecificVariation = !string.IsNullOrEmpty(_variationName);

        var needsResult = _positionAtClosestColliderPoint || _exitMode == MasterAudio.AmbientSoundExitMode.FadeSound;

        if (fadingVariation != null && fadingVariation.ActingVariation != null)
        {
            var reEnterModeToUse = _reEnterMode;

            if (!fadingVariation.ActingVariation.IsPlaying)
            {
                reEnterModeToUse = MasterAudio.AmbientSoundReEnterMode.StopExistingSound; // it cannot fade it back in if it already stopped.
            }

            switch (reEnterModeToUse)
            {
            case MasterAudio.AmbientSoundReEnterMode.FadeInSameSound:
                fadingVariation.ActingVariation.FadeToVolume(_playVolume, _reEnterFadeTime);
                playingVariation = fadingVariation;

                fadingVariation = null;
                _hasPlayedSound = true;
                return;

            case MasterAudio.AmbientSoundReEnterMode.StopExistingSound:
                fadingVariation.ActingVariation.Stop();
                break;
            }
        }

        if (_willFollowSource)
        {
            if (needsResult)
            {
                if (hasSpecificVariation)
                {
                    playingVariation = MasterAudio.PlaySound3DFollowTransform(_soundType, RuntimeFollowingTransform, _playVolume, 1f, 0f, _variationName);
                }
                else
                {
                    playingVariation = MasterAudio.PlaySound3DFollowTransform(_soundType, RuntimeFollowingTransform, _playVolume);
                }
            }
            else
            {
                if (hasSpecificVariation)
                {
                    MasterAudio.PlaySound3DFollowTransformAndForget(_soundType, RuntimeFollowingTransform, _playVolume, 1f, 0f, _variationName);
                }
                else
                {
                    MasterAudio.PlaySound3DFollowTransformAndForget(_soundType, RuntimeFollowingTransform, _playVolume);
                }
            }
        }
        else
        {
            if (needsResult)
            {
                if (hasSpecificVariation)
                {
                    playingVariation = MasterAudio.PlaySound3DAtTransform(_soundType, RuntimeFollowingTransform, _playVolume, 1f, 0f, _variationName);
                }
                else
                {
                    playingVariation = MasterAudio.PlaySound3DAtTransform(_soundType, RuntimeFollowingTransform, _playVolume);
                }
            }
            else
            {
                if (hasSpecificVariation)
                {
                    MasterAudio.PlaySound3DAtTransformAndForget(_soundType, RuntimeFollowingTransform, _playVolume, 1f, 0f, _variationName);
                }
                else
                {
                    MasterAudio.PlaySound3DAtTransformAndForget(_soundType, RuntimeFollowingTransform, _playVolume);
                }
            }
        }

        fadingVariation = null;
        _hasPlayedSound = true;
    }
    private static PlaySoundResult PlaySoundIfAvailable(string soundGroupName,
            AudioInfo info,
            Vector3 sourcePosition,
            float volumePercentage,
            ref bool forgetSoundPlayed,
            float? pitch = null,
            AudioGroupInfo audioGroup = null,
            Transform sourceTrans = null,
            bool attachToSource = false,
            float delaySoundTime = 0f,
            bool useVector3 = false,
            bool makePlaySoundResult = false,
			bool isChaining = false)
    {

        if (info.source == null)
        {
            // this avoids false errors when stopping the game (from became invisible event callers)
            return null;
        }

        MasterAudioGroup maGroup = audioGroup._group;

        if (info.source.audio.isPlaying)
        {
            var playedPercentage = AudioUtil.GetAudioPlayedPercentage(info.source);
            var retriggerPercent = maGroup.retriggerPercentage;

            if (playedPercentage < retriggerPercent)
            {
                return null; // wait for this to stop playing or play further.
            }
        }

        info.variation.Stop();
        info.variation.ObjectToFollow = null;

        if (useVector3)
        {
            info.source.transform.position = sourcePosition;
            if (MasterAudio.Instance.prioritizeOnDistance)
            {
                AudioPrioritizer.Set3dPriority(info.source);
            }
        }
        else if (sourceTrans != null)
        {
            if (attachToSource)
            {
                info.variation.ObjectToFollow = sourceTrans;
            }
            else
            {
                info.source.transform.position = sourceTrans.position;
            }

            if (MasterAudio.Instance.prioritizeOnDistance)
            {
                AudioPrioritizer.Set3dPriority(info.source);
            }
        }
        else
        {
            // "2d manner"
            if (MasterAudio.Instance.prioritizeOnDistance)
            {
                AudioPrioritizer.Set2dSoundPriority(info.source);
            }
            info.source.transform.localPosition = Vector3.zero; // put it back in MA prefab position after being detached.
        }

        var groupVolume = maGroup.groupMasterVolume;
        var busVolume = GetBusVolume(maGroup);

        float calcVolume = info.originalVolume * groupVolume * busVolume * MasterAudio.Instance.masterAudioVolume;

        // set volume to percentage.
        float volume = calcVolume * volumePercentage;

        // random volume
        var randomVol = 0f;
        if (info.variation.randomVolume != 0f)
        {
            randomVol = UnityEngine.Random.Range(-info.variation.randomVolume, info.variation.randomVolume);
        }

        var targetVolume = volume + randomVol;

        info.source.audio.volume = targetVolume;

        // save these for on the fly adjustments afterward
        info.lastPercentageVolume = volumePercentage;
        info.lastRandomVolume = randomVol;

        bool isActive = false;

#if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
        isActive = info.source.audio.gameObject.active;
#else
			isActive = info.source.audio.gameObject.activeInHierarchy;
#endif

        if (!isActive)
        {
            return null;
        }

        PlaySoundResult result = null;

        if (makePlaySoundResult)
        {
            result = new PlaySoundResult();
            result.ActingVariation = info.variation;

            if (delaySoundTime > 0f)
            {
                result.SoundScheduled = true;
            }
            else
            {
                result.SoundPlayed = true;
            }
        }
        else
        {
            forgetSoundPlayed = true;
        }

        var playSoundParams = new SoundGroupVariation.PlaySoundParams(maGroup.name,
              volumePercentage,
              calcVolume,
              pitch,
              sourceTrans,
              attachToSource,
              delaySoundTime,
              maGroup.curVariationMode == MasterAudioGroup.VariationMode.LoopedChain);

		
		if (playSoundParams.isChainLoop && !isChaining) {
			maGroup.ChainLoopCount = 0;
		}
		
        if (playSoundParams.isChainLoop)
        {
            // make sure there isn't 2 going, ever
            MasterAudio.StopAllOfSound(playSoundParams.soundType);
        }

        info.variation.Play(pitch, targetVolume, playSoundParams);

        if (delaySoundTime == 0f)
        {
            // sound play worked! Duck music if a ducking sound.
            var ma = MasterAudio.Instance;

            var matchingDuck = ma.musicDuckingSounds.Find(delegate(DuckGroupInfo obj)
            {
                return obj.soundType == soundGroupName;
            });

            if (ma.EnableMusicDucking && matchingDuck != null)
            {
                // duck music
                var duckLength = info.source.audio.clip.length;
                var duckPitch = info.source.pitch;

                var pcs = PlaylistController.Instances;
                for (var i = 0; i < pcs.Count; i++)
                {
                    pcs[i].DuckMusicForTime(duckLength, duckPitch, matchingDuck.riseVolStart);
                }

                if (pcs.Count == 0)
                {
                    Debug.LogWarning("Playlist Controller is not in the Scene. Cannot duck music.");
                }
            }
        }


        return result;
    }