Пример #1
0
    //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);
        try
        {
            AudioMixerGroup   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");
        }
        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));
    }