示例#1
0
    public GameObject playSoundSFX(SOUND_NAME type)
    {
        //		Debug.Log("playSound : " + type);
        GameObject retVal = null;
        bool       flag   = true;

        if (soundSFX[type] != null)
        {
            GameObject sound = (GameObject)soundSFX[type];
            if (sound != null)
            {
                sound.GetComponent <AudioSource>().Play();
                retVal = sound;
                //			Debug.Log("Play 1");
                flag = false;
            }
            else
            {
                soundSFX.Remove(type);
            }
        }

        if (flag)
        {
            AudioClip sound = getSound(type);

            GameObject audioSource = new GameObject("AudioSource", typeof(AudioSource));
            audioSource.transform.parent = transform;
            audioSource.GetComponent <AudioSource>().clip = sound;
            audioSource.name = type.ToString();
            soundSFX.Add(type, audioSource);
            audioSource.GetComponent <AudioSource>().spatialBlend = 0.0f;
            audioSource.GetComponent <AudioSource>().Play();

            retVal = audioSource;
        }

        recheckAllSound();
        return(retVal);
    }
示例#2
0
    public GameObject playSoundBackGround(SOUND_NAME type)
    {
        GameObject retVal = null;

        if (currentThemeSound == type)
        {
            return(null);
        }

        if (soundBG[type] != null)
        {
            GameObject sound = (GameObject)soundBG[type];
            if (sound != null)
            {
                sound.GetComponent <AudioSource>().Play();
                sound.GetComponent <AudioSource>().volume = 1f;
                retVal = sound;
            }
            else
            {
                soundBG.Remove(type);
            }
        }

        if (retVal == null)
        {
            AudioClip clipAudio = getSound(type);

            GameObject  go          = new GameObject("AudioSource", typeof(AudioSource));
            AudioSource audioSource = go.GetComponent <AudioSource>();
            go.transform.parent = transform;
            go.name             = type.ToString();
            soundBG.Add(type, go);

            audioSource.clip         = clipAudio;
            audioSource.loop         = true;
            audioSource.spatialBlend = 0.0f;
            audioSource.volume       = 1f;
            audioSource.Play();

            retVal = go;
        }

        if (currentThemeSound != SOUND_NAME.None)
        {
            if (soundBG[currentThemeSound] != null)
            {
                GameObject sound = (GameObject)soundBG[currentThemeSound];
                if (sound != null)
                {
                    sound.GetComponent <AudioSource>().Stop();
                }
                else
                {
                    soundBG.Remove(currentThemeSound);
                }
            }
        }

        currentThemeSound = type;
        recheckAllSound();

        return(retVal);
    }