Exemplo n.º 1
0
        /// <summary>
        /// 即刻播放声音
        /// </summary>
        /// <param name="name"></param>
        public SoundClip playSound(string name, bool isFroce = false, bool isUI = false)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            SoundClip soundClip = null;

            if (_soundsDictionary.TryGetValue(name, out soundClip))
            {
                soundClip.soundValue = soundValue;
                if (soundClip.isPlaying == false)
                {
                    soundClip.Play();
                }
                else if (isFroce)
                {
                    soundClip.time = 0f;
                }
                return(soundClip);
            }

            soundClip = getSoundInstance();
            _soundsDictionary.Add(name, soundClip);

            soundClip.soundValue = soundValue;
            soundClip.name       = name;
            soundClip.addEventListener(EventX.COMPLETE, completeHandle);

            string url = getURL(name, isUI);

            soundClip.load(url);

            return(soundClip);
        }