Beispiel #1
0
    private static AudioSource PlaySound(GameSounds.Sound sound, bool loop, GameObject from = null, Action callback = null)
    {
        if (sound.Clip == null)
        {
            return(null);
        }

        bool destroy = from == null;

        if (destroy)
        {
            from = new GameObject("Sound_" + sound.Clip.name, typeof(AudioSource));
        }

        AudioSource source = from.GetComponent <AudioSource>();

        if (source == null)
        {
            source = from.AddComponent <AudioSource>();
        }

        AudioMixerGroup group = null;

        switch (sound.Type)
        {
        case GameSounds.SoundType.Music:
            group = _MusicGroup;
            break;

        case GameSounds.SoundType.Action:
            group = _ActionGroup;
            break;

        case GameSounds.SoundType.Signe:
            group = _SigneGroup;
            break;

        case GameSounds.SoundType.Feedback:
            group = _FeedbackGroup;
            break;

        case GameSounds.SoundType.Fin:
            group = _FinGroup;
            break;
        }
        source.outputAudioMixerGroup = group;
        source.clip = sound.Clip;
        source.loop = loop;

        if (loop)
        {
            source.Play();
        }
        else
        {
            instance.StartCoroutine(instance.PlayClip(source, callback, destroy));
        }
        return(source);
    }
Beispiel #2
0
 public static void PlayLoop(GameSounds.Sound sound)
 {
     if (sound.Type == GameSounds.SoundType.Music)
     {
         if (_CurrentMusicSource != null)
         {
             instance.StartCoroutine(instance.FadeOut(PlaySound(sound, true, null, null), _CurrentMusicSource, 2f));
         }
         else
         {
             _CurrentMusicSource = PlaySound(sound, true, null, null);
         }
     }
 }
Beispiel #3
0
 public static void PlaySingleShot(GameSounds.Sound sound, GameObject from = null, Action callback = null)
 {
     PlaySound(sound, false, from, callback);
 }
Beispiel #4
0
 public static void PlaySingleShot(GameSounds.Sound sound, Action callback)
 {
     PlaySound(sound, false, null, callback);
 }