private GameObject getAudioSourcePrefab(AppAudioClip clip)
 {
     //TODO add separate audio source for bg music, or use the same as fanfar
     if (clip == AppAudioClip.IntroFanfare)
     {
         return(_audioSourceMusicPrefab);
     }
     else
     {
         return(_audioSourcePrefab);
     }
 }
    public void playClip(AppAudioClip clip)
    {
        if (_muted)
        {
            Debug.Log("AudioManager Muted, not playing anything");
            return;
        }
        //Debug.Log("AudioManager play clip " + clip);

        string path = ClipPath(clip);

        Debug.Assert(path != null);

        if (path != null)
        {
            //AudioClip playMe = (AudioClip)Resources.Load(path, typeof(AudioClip));//Resources.Load(path) as AudioClip;
            AudioClip playMe = Resources.Load <AudioClip>(path);
            Debug.Assert(playMe != null);
            if (playMe != null)
            {
                //Debug.Log("AudioManager clip loaded " + playMe);

                //we have to use separate audiosources per clip, for polyphony
                GameObject audioSource = Instantiate(getAudioSourcePrefab(clip)) as GameObject;
                audioSource.transform.SetParent(this.transform);


                AudioSource source = audioSource.GetComponent <AudioSource>();
                Debug.Assert(source != null);
                _currentlyPlaying.Add(source);

                source.clip = playMe;

                source.Play();                //or PlayOneShot

                //cleanup after finished
                float timeInSecs = playMe.length;
                Debug.Assert(timeInSecs > 0.0f);
                if (timeInSecs <= 0.0f)
                {
                    //some safety programming. important is that the clip get's cleaned up at some point
                    Debug.LogWarning("[AudioManager]: clip length reported " + timeInSecs);
                    timeInSecs = 10.0f;
                }
                StartCoroutine(cleanUpFinished(audioSource, timeInSecs));
            }
        }
    }
    private string ClipPath(AppAudioClip clip)
    {
        string path = null;

        switch (clip)
        {
        case AppAudioClip.Explosion:            return("Audio/explosion_player");

        case AppAudioClip.AcquireWeapon:        return("Audio/pick_up_1");

        case AppAudioClip.AcquireSpeedup:       return("Audio/pick_up_2");

        case AppAudioClip.AcquireEnlarge:       return("Audio/pick_up_3");

        case AppAudioClip.Shoot:                        return("Audio/weapon_enemy_quieter");

        case AppAudioClip.IntroFanfare:     return("Audio/fanfare");

        case AppAudioClip.AsteroidRumble:   return("Audio/asteroid_rumble_mid");
        }

        return(path);
    }