コード例 #1
0
ファイル: SoundManager.cs プロジェクト: Zeldarck/PapyProject
    //TODO see to move initialisation of audiosource elsewhere - store key inside audio extends instead of dictionnary?
    //TODO : Store a part of audioclips here and associate key

    /// <summary>
    /// Start an audio depending of parameters - TODO simplify it and move elswhere some logic
    /// </summary>
    /// <param name="a_clip">Clip we want to play</param>
    /// <param name="a_mixerGroupType">Mixer we want to output</param>
    /// <param name="a_isFading">If the clip is fading</param>
    /// <param name="a_isLooping">If the clip it autolooping</param>
    /// <param name="a_key">the key we want</param>
    /// <param name="a_delay">if we play with a delay</param>
    /// <returns></returns>
    public int StartAudio(AudioClip a_clip, MIXER_GROUP_TYPE a_mixerGroupType = MIXER_GROUP_TYPE.AMBIANT, bool a_isFading = true, bool a_isLooping = true, AUDIOSOURCE_KEY a_key = AUDIOSOURCE_KEY.CREATE_KEY, ulong a_delay = 0)
    {
        int res = -1;
        int key = (int)a_key;

        res = GetKey(key);
        AudioMixerGroup mixer = null;

        try
        {
            mixer = m_listMixerGroup.Find(x => x.MixerType == a_mixerGroupType).MixerGroup;
            AudioSourceExtend source;

            if (GetAudioSource(key, out source))
            {
                if (source.AudioSource.clip == a_clip)
                {
                    Debug.Log("Clip ever play : " + a_clip.name);
                    return(key);
                }
                AudioSourceExtend new_source = new AudioSourceExtend(CreateAudioSource());
                m_audioSourcesExtend.Add(new_source);
                m_audioSourcesExtendWithKey[key] = new_source;
                if (a_isFading)
                {
                    source.Speed = -m_speedFade;
                }
                else
                {
                    source.Stop();
                }
                source.AutoDestroy = true;
                AudioSourceExtend temp = source;
                source     = new_source;
                new_source = temp;
            }

            if (a_isFading)
            {
                source.Speed = m_speedFade;
                source.AudioSource.volume = 0;
            }

            source.AudioSource.outputAudioMixerGroup = mixer;
            source.AudioSource.clip = a_clip;
            source.AudioSource.loop = a_isLooping;
            source.AudioSource.Play(a_delay);

            Debug.Log("StartAudio : " + a_clip.name);
        }
        catch
        {
            Debug.LogError("Error when try to launch sound");
            if (mixer == null)
            {
                Debug.LogError("Mixer doesn't exist");
            }
        }
        return(res);
    }
コード例 #2
0
    public int StartAudio(AUDIOCLIP_KEY a_clipKey, MIXER_GROUP_TYPE a_mixerGroupType = MIXER_GROUP_TYPE.AMBIANT, bool a_isFading = true, bool a_isLooping = true, AUDIOSOURCE_KEY a_key = AUDIOSOURCE_KEY.CREATE_KEY, ulong a_delay = 0)
    {
        AudioClipLink audioClip = m_listAudioClip.Find(o => o.Key == a_clipKey);

        Assert.IsFalse(audioClip == null, "Bad audioclip key");

        return(StartAudio(audioClip.AudioClip, a_mixerGroupType, a_isFading, a_isLooping, a_key, a_delay));
    }
コード例 #3
0
    public void SetMixerVolume(MIXER_GROUP_TYPE a_mixerGroupType, float a_volume)
    {
        MixerGroupLink mixer = m_listMixerGroup.Find(x => x.MixerType == a_mixerGroupType);

        Assert.AreNotEqual(mixer, null, "MixerGroup don't exist");

        mixer.MixerGroup.audioMixer.SetFloat(mixer.VolumeVariable, a_volume);
    }
コード例 #4
0
    public float GetMixerVolume(MIXER_GROUP_TYPE a_mixerGroupType)
    {
        float          res   = 0;
        MixerGroupLink mixer = m_listMixerGroup.Find(x => x.MixerType == a_mixerGroupType);

        Assert.AreNotEqual(mixer, null, "MixerGroup don't exist");

        mixer.MixerGroup.audioMixer.GetFloat(mixer.VolumeVariable, out res);
        return(res);
    }
コード例 #5
0
    /// <summary>
    /// Start an audio of a random bank
    /// </summary>
    /// <param name="a_randomSoundType">id of the random bank</param>
    /// <param name="a_mixerGroupType">id of the mixer we want to output through</param>
    public void StartRandom(RANDOM_SOUND_TYPE a_randomSoundType, MIXER_GROUP_TYPE a_mixerGroupType)
    {
        RandomSound randomSound = m_listRandomSound.Find(x => x.Type == a_randomSoundType);

        if (randomSound.ListSounds.Count > 0)
        {
            int       rnd    = (int)Utils.RandomFloat(0, randomSound.ListSounds.Count);
            AudioClip toPlay = randomSound.ListSounds[rnd];
            randomSound.AudioSourceKey = StartAudio(randomSound.ListSounds[rnd], a_mixerGroupType, false, false, (AUDIOSOURCE_KEY)randomSound.AudioSourceKey);
            randomSound.EverUsed.Add(toPlay);
            randomSound.ListSounds.Remove(toPlay);

            if (randomSound.ListSounds.Count == 0)
            {
                randomSound.ListSounds.AddRange(randomSound.EverUsed);
                randomSound.EverUsed.Clear();
            }
        }
    }