Exemplo n.º 1
0
    IEnumerator FadeSoundOut(string name, float time)
    {
        Debug.Log("Fading out sound " + name + " in " + time);

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

        if (s == null)
        {
            Debug.LogWarning("Der Sound " + name + " wurde im AudioManager nicht gefunden.");
        }
        if (s.source == null)
        {
            Debug.Log("The sound " + name + " will be dynamically loaded.");
            LoadSoundSource(s);
        }
        for (int i = 0; i < time * 25; i++)
        {
            s.source.volume -= i / (time * 25);
            yield return(new WaitForSecondsRealtime(.04f));
        }
        s.source.Stop();

        Debug.Log("Sound " + name + " faded out");
        s.source.volume = s.volume;
    }
Exemplo n.º 2
0
    void UnloadSoundSource(ArcticSound s)
    {
        if (s.source == null)
        {
            return;
        }

        Destroy(s.source);
        s.source = null;
    }
Exemplo n.º 3
0
    void LoadSoundSource(ArcticSound s)
    {
        if (s.source != null)
        {
            return;
        }

        s.source        = gameObject.AddComponent <AudioSource>();
        s.source.clip   = s.clip;
        s.source.volume = s.volume;
        s.source.pitch  = s.pitch;
        s.source.loop   = s.loop;
        s.source.outputAudioMixerGroup = s.mixerGroup;
    }
Exemplo n.º 4
0
    public void UnPause(string name)
    {
        ArcticSound s = Array.Find(sounds, sound => sound.name == name);

        if (s == null)
        {
            Debug.LogWarning("Der Sound " + name + " wurde im AudioManager nicht gefunden.");
            return;
        }
        if (s.source == null)
        {
            Debug.Log("The sound " + name + " will be dynamically loaded.");
            LoadSoundSource(s);
        }
        s.source.UnPause();
    }
Exemplo n.º 5
0
    IEnumerator PitchDown(string name, float downTo, float transitionDuration)
    {
        ArcticSound s = Array.Find(sounds, sound => sound.name == name);

        if (s == null)
        {
            Debug.LogWarning("Der Sound " + name + " wurde im AudioManager nicht gefunden.");
        }
        if (s.source == null)
        {
            Debug.Log("The sound " + name + " will be dynamically loaded.");
            LoadSoundSource(s);
        }
        for (int i = 0; i < transitionDuration * 25; i++)
        {
            s.source.pitch = Mathf.Lerp(s.pitch, downTo, i / transitionDuration * 25);
            yield return(new WaitForSecondsRealtime(.04f));
        }
    }
Exemplo n.º 6
0
    public void Play(string name, bool onlyPlayIfNotAlreadyPlaying)
    {
        ArcticSound s = Array.Find(sounds, sound => sound.name == name);

        if (s == null)
        {
            Debug.LogWarning("The sound " + name + " has not been found.");
            return;
        }
        if (s.source == null)
        {
            Debug.Log("The sound " + name + " will be dynamically loaded.");
            LoadSoundSource(s);
        }

        if (onlyPlayIfNotAlreadyPlaying && !s.source.isPlaying)
        {
            s.source.Play();
        }
    }
Exemplo n.º 7
0
    public void Play(string name)
    {
        ArcticSound s = Array.Find(sounds, sound => sound.name == name);

        if (s == null)
        {
            Debug.LogWarning("The sound " + name + " has not been found.");
            return;
        }
        if (s.source == null)
        {
            Debug.Log("The sound " + name + " will be dynamically loaded.");
            LoadSoundSource(s);
        }
        if (s.source == null)
        {
            Debug.LogError("The sound " + name + " could not be loaded.");
            return;
        }

        s.source.Play();
    }