Exemple #1
0
    public float GetVolume(MixerGroup group)
    {
        string volumeName = GetMixerGroupVolumeName(group);

        masterMixer.GetFloat(volumeName, out float value);
        return(DecibelToLinear(value));
    }
Exemple #2
0
    private void OnMixerGroupValue(MixerGroup _mixerGroup, float _volume)
    {
        int vol = (int)_volume;

        switch (_mixerGroup)
        {
        case MixerGroup.MASTER:
            masterVolumeText.text    = $"{(vol + 80)} %";
            masterVolumeSlider.value = _volume;
            break;

        case MixerGroup.SFX:
            sfxVolumeText.text    = $"{(vol + 80)} %";
            sfxVolumeSlider.value = _volume;
            break;

        case MixerGroup.ATMO:
            atmoVolumeText.text    = $"{(vol + 80)} %";
            atmoVolumeSlider.value = _volume;
            break;

        case MixerGroup.MUSIC:
            musicVolumeText.text    = $"{(vol + 80)} %";
            musicVolumeSlider.value = _volume;
            break;
        }
    }
Exemple #3
0
        public static PooledAudioSource PlayAudio(ArdenAudioClip clip, MixerGroup group = MixerGroup.ui, float volume = 1, bool looped = false, AudioSourceSettings settings = null)
        {
            if (clip == null)
            {
                return(null);
            }

            return(PlayPooledClip(clip.audioClip, group, clip.volume * volume, clip.GetPitch(), looped, settings));
        }
Exemple #4
0
    public AudioSource Play(MixerGroup group, string resource, float volume = 1f)
    {
        AudioClip   clip        = Resources.Load <AudioClip>(resource);
        AudioSource audioSource = GetAudioSource(resource);

        audioSource.outputAudioMixerGroup = audioMixerGroups[group];
        audioSource.PlayOneShot(clip, volume);
        return(audioSource);
    }
Exemple #5
0
        public void Init(float volume, MixerGroup group, bool playAtPoint, Vector3 position)
        {
            this.volume      = volume;
            this.group       = group;
            this.playAtPoint = playAtPoint;
            this.position    = position;

            currentlyPlayingChildren = new List <ArdenAudioInstance>();
            Play();
        }
Exemple #6
0
 //Returns a mixer group via the enum
 public static AudioMixerGroup GetMixerGroup(MixerGroup group)
 {
     foreach (MixerGroupObject g in Instance.mixerObjects)
     {
         if (g.group == group)
         {
             return(g.asset);
         }
     }
     return(null);
 }
Exemple #7
0
    public void SetVolume(MixerGroup group, float value, bool save = true)
    {
        string volumeName   = GetMixerGroupVolumeName(group);
        float  decibelValue = LinearToDecibel(value);

        masterMixer.SetFloat(volumeName, decibelValue);
        if (save)
        {
            PlayerPrefs.SetFloat(volumeName, value);
        }
    }
Exemple #8
0
    public AudioSource PlaySound2D(string soundId, MixerGroup mixerGroup = MixerGroup.None, float volume                 = 1f, float skipToTime = 0f, AudioParams.Pitch pitch = null,
                                   AudioParams.Repetition repetition     = null, AudioParams.Randomization randomization = null, AudioParams.Distortion distortion = null, bool looping = false)
    {
        var source = PlaySound3D(soundId, Vector3.zero, mixerGroup, volume, skipToTime, pitch, repetition, randomization, distortion, looping);

        if (source != null)
        {
            source.spatialBlend = 0f;
        }

        return(source);
    }
Exemple #9
0
        public void Init(float volume, MixerGroup group, bool looped, bool playAtPoint, Vector3 position)
        {
            this.volume      = volume;
            this.group       = group;
            this.looped      = looped;
            this.playAtPoint = playAtPoint;
            this.position    = position;

            playedChildren = new List <int>();

            //Start playing
            NextChild();
        }
Exemple #10
0
    public AudioSource PlaySound(AudioClip sound, Vector3 position, MixerGroup mixerGroup = MixerGroup.SFX, float volume = 0.95f)
    {
        if (_pool == null)
        {
            Debug.LogError("No pool set!");
        }

        var source = SpawnSound(sound, position, group: mixerGroup);

        source.volume = volume;

        return(source);
    }
    public void PlaySound(string name, MixerGroup group)

    /* This method is called to play a sound
     * Sounds can be added to the sounds array in the inspector
     *
     * example usage:
     * FindObjectOfType<GameManager>().PlaySound("ExampleSound");
     */

    {
        Sound s = Array.Find(sounds, sound => sound.name == name);

        if (s == null)
        {
            Debug.Log("sound with name " + name + " can not be found!");
            return;
        }

        switch (group)
        {
        case MixerGroup.Master:
        {
            s.source.outputAudioMixerGroup = masterAudioMixerGroup;
            break;
        }

        case MixerGroup.Music:
        {
            s.source.outputAudioMixerGroup = musicAudioMixerGroup;
            break;
        }

        case MixerGroup.SFX:
        {
            s.source.outputAudioMixerGroup = sfxAudioMixerGroup;
            break;
        }

        default:
        {
            Debug.Log("No audio mixer with that name found, using default one");
            s.source.outputAudioMixerGroup = masterAudioMixerGroup;
            break;
        }
        }

        if (!s.source.isPlaying)
        {
            s.source.Play();
        }
    }
Exemple #12
0
    AudioSource BuildAudioSource(MixerGroup group = MixerGroup.SFX, bool loop = false)
    {
        var soundPrefab = new GameObject();

        soundPrefab.transform.SetParent(_container.transform);
        var source = soundPrefab.AddComponent <AudioSource>();

        source.playOnAwake  = false;
        source.spatialBlend = 0f;
        source.Stop();
        SetMixerGroup(source, group);
        source.loop = loop;
        return(source);
    }
Exemple #13
0
        private void InitializeSoundArray(Sound[] soundArray, MixerGroup group)
        {
            foreach (Sound s in soundArray)
            {
                switch (group)
                {
                case MixerGroup.Music:
                    s.source      = gameObject.AddComponent <AudioSource>();
                    s.source.clip = s.clip;
                    s.source.outputAudioMixerGroup = music;
                    break;

                case MixerGroup.Effects:
                    s.mixerGroup = effects;
                    break;
                }
            }
        }
Exemple #14
0
    public static void Create3DSound(Vector3 position, AudioClip clip, MixerGroup mixerGroup, float volume, float minPitch, float maxPitch, int priority = 128, float minDistance = 5f)
    {
        GameObject  sound = new GameObject("temporary sound");
        AudioSource a     = sound.AddComponent <AudioSource>();

        a.clip         = clip;
        a.volume       = volume;
        a.pitch        = Mathf.Lerp(minPitch, maxPitch, Random.value);
        a.spatialBlend = 1;
        a.minDistance  = minDistance;
        a.priority     = priority;

        sound.transform.SetParent(LevelLoader.TemporaryObjects);
        sound.AddComponent <DestroyAfterSoundPlayed>();
        sound.transform.position = position;

        switch (mixerGroup)
        {
        default:
        case MixerGroup.Master:
            a.outputAudioMixerGroup = MixerDesignator.MasterMixerGroup;
            break;

        case MixerGroup.Music:
            a.outputAudioMixerGroup = MixerDesignator.MusicMixerGroup;
            break;

        case MixerGroup.Effects:
            a.outputAudioMixerGroup = MixerDesignator.EffectsMixerGroup;
            break;

        case MixerGroup.Ambient:
            a.outputAudioMixerGroup = MixerDesignator.AmbientMixerGroup;
            break;

        case MixerGroup.Interface:
            a.outputAudioMixerGroup = MixerDesignator.InterfaceMixerGroup;
            break;
        }

        a.Play();
    }
Exemple #15
0
    public AudioSource PlaySound3D(string soundId, Vector3 position, MixerGroup mixerGroup = MixerGroup.None, float volume = 1f, float skipToTime = 0f, AudioParams.Pitch pitch           = null,
                                   AudioParams.Repetition repetition = null, AudioParams.Randomization randomization       = null, AudioParams.Distortion distortion = null, bool looping = false)
    {
        if (repetition != null)
        {
            if (RepetitionIsTooFrequent(soundId, repetition.minRepetitionFrequency, repetition.entryId))
            {
                return(null);
            }
        }

        string randomVariationId = soundId;

        if (randomization != null)
        {
            randomVariationId = GetRandomVariationOfSound(soundId, randomization.noRepeating);
        }

        var source = CreateAudioSourceForSound(randomVariationId, position, looping, mixerGroup);

        if (source != null)
        {
            source.volume = volume;
            source.time   = source.clip.length * skipToTime;

            if (pitch != null)
            {
                source.pitch = pitch.pitch;
            }

            if (distortion != null)
            {
                if (distortion.muffled)
                {
                    MuffleSource(source);
                }
            }
        }

        activeSFX.Add(source);
        return(source);
    }
Exemple #16
0
        //Play 2D audio source by randomly selecting from list
        public static PooledAudioSource PlayAudio(List <ArdenAudioClip> clips, MixerGroup group = MixerGroup.ui, float volume = 1, bool looped = false, AudioSourceSettings settings = null)
        {
            if (clips == null)
            {
                return(null);
            }

            if (clips.Count == 0)
            {
                return(null);
            }

            if (clips.Count == 1)
            {
                return(PlayPooledClip(clips[0].audioClip, group, clips[0].volume * volume, clips[0].GetPitch(), looped, settings));
            }

            int r = UnityEngine.Random.Range(0, clips.Count);

            return(PlayPooledClip(clips[r].audioClip, group, clips[r].volume * volume, clips[r].GetPitch(), looped, settings));
        }
Exemple #17
0
    void SetMixerGroup(AudioSource source, MixerGroup group)
    {
        switch (group)
        {
        case MixerGroup.SFX:
            source.outputAudioMixerGroup = MixerGroupSFX;
            break;

        case MixerGroup.Music:
            source.outputAudioMixerGroup = MixerGroupMusic;
            break;

        case MixerGroup.Title:
            source.outputAudioMixerGroup = MixerGroupTitleSFX;
            break;

        case MixerGroup.Announcer:
            source.outputAudioMixerGroup = MixerGroupAnnouncer;
            break;

        default:
            break;
        }
    }
Exemple #18
0
    private AudioSource SpawnSound(AudioClip sound, Vector3 position, bool is3D = false, MixerGroup group = MixerGroup.SFX)
    {
        var soundInstance = _pool.spawnObject(
            _prefab,
            position,
            Quaternion.identity).GetCreateComponent <AudioSource>();

        soundInstance.transform.SetParent(_container.transform);
        soundInstance.spatialBlend = is3D ? 1f : 0f;
        soundInstance.clip         = sound;
        SetMixerGroup(soundInstance, group);
        soundInstance.Play();

        StartCoroutine(SpawnSoundRoutine(soundInstance));

        return(soundInstance);
    }
Exemple #19
0
 private string GetMixerGroupVolumeName(MixerGroup group)
 {
     return(group.ToString() + VolumePostfix);
 }
        public override ArdenAudioInstance Play(AudioSourceSettings settings, float volume = 1, MixerGroup group = MixerGroup.sfx, bool looped = false)
        {
            int r = Random.Range(0, audioClips.Count);

            return(audioClips[r].Play(settings, volume, group, looped));
        }
 public virtual ArdenAudioInstance PlayAtPoint(Vector3 location, float volume = 1, MixerGroup group = MixerGroup.sfx, bool looped = false)
 {
     return(PlayAtPoint(new AudioSourceSettings(), location, volume, group, looped));
 }
 public virtual ArdenAudioInstance Play(AudioSourceSettings settings, float volume = 1, MixerGroup group = MixerGroup.sfx, bool looped = false)
 {
     return(null);
 }
 public virtual ArdenAudioInstance Play(float volume = 1, MixerGroup group = MixerGroup.sfx, bool looped = false)
 {
     return(Play(new AudioSourceSettings(), volume, group, looped));
 }
Exemple #24
0
        //A single function to unify play and play at point, under the hood
        protected ArdenAudioInstance Play_Internal(AudioSourceSettings settings, float volume, MixerGroup group, bool looped, bool playAtPoint, Vector3 location)
        {
            if (layers == null)
            {
                return(null);
            }

            if (layers.Count == 0)
            {
                return(null);
            }

            ArdenAudioMixerInstance instance = new ArdenAudioMixerInstance(this, settings);

            instance.Init(volume, group, playAtPoint, location);

            return(instance);
        }
Exemple #25
0
 public override ArdenAudioInstance PlayAtPoint(AudioSourceSettings settings, Vector3 location, float volume = 1, MixerGroup group = MixerGroup.sfx, bool looped = false)
 {
     return(Play_Internal(settings, volume, group, looped, true, location));
 }
Exemple #26
0
 public void OnMixerGroupVolumeChanged(MixerGroup _mixerGroup, float _volume)
 {
     MixerGroupVolumeChanged?.Invoke(_mixerGroup, _volume);
 }
Exemple #27
0
    private AudioSource CreateAudioSourceForSound(string soundId, Vector3 position, bool looping, MixerGroup mixerGroup = MixerGroup.None)
    {
        if (!string.IsNullOrEmpty(soundId))
        {
            AudioClip sound = SFX.Find(x => x.name.ToLower() == soundId.ToLower());

            if (sound != null)
            {
                return(InstantiateAudioObject(sound, position, looping));
            }
        }

        return(null);
    }
        public override ArdenAudioInstance Play(AudioSourceSettings settings, float volume, MixerGroup group = MixerGroup.sfx, bool looped = false)
        {
            PooledAudioSource source = SoundManager.PlayPooledClip(audioClip, group, volume * this.volume, GetPitch(), looped, settings);

            ArdenAudioClipInstance instance = new ArdenAudioClipInstance(this, settings);

            instance.Init(source);

            return(instance);
        }
Exemple #29
0
 public override ArdenAudioInstance Play(AudioSourceSettings settings, float volume = 1, MixerGroup group = MixerGroup.sfx, bool looped = false)
 {
     return(Play_Internal(settings, volume, group, looped, false, new Vector3()));
 }
Exemple #30
0
 public static AudioMixerGroup GetGroup(MixerGroup group) => _mixerGroups[group];