예제 #1
0
    public void SetMusic(string audio)
    {
        AudioClip value;

        if (m_SoundDic.TryGetValue(audio, out value))
        {
            m_MusicSource.Stop();
            m_MusicSource.clip = value;
            m_MusicSource.Play();
            m_MusicSource.enabled = false;
            m_MusicSource.enabled = true;
        }
    }
예제 #2
0
    public bool Play(string chanel, string sound, PlayMode mode = PlayMode.OneShot)
    {
        // try get data
        if (m_SoundDictionary.TryGetValue(sound, out var audioClip) &&
            m_ChanelDictionary.TryGetValue(chanel, out var audioSource))
        {
            switch (mode)
            {
            case PlayMode.OneShot:
                audioSource.PlayOneShot(audioClip);
                return(true);

            case PlayMode.Source:
                audioSource.clip = audioClip;
                audioSource.Play();
                return(true);

            default:
                throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
            }
        }

        return(false);
    }
예제 #3
0
        public void Play(string name)
        {
            SoundData data;

            Console.WriteLine(string.Format("Try to play sound {0}.", name));

            if (SoundDictionary.TryGetValue(name, out data))
            {
                SoundEffectInstance sound = _soundEffects[data.Name];
                if ((_currentSoundData.Priority <= data.Priority || _currentSound.State != SoundState.Playing) && sound.State != SoundState.Playing)
                {
                    if (_currentSound != null)
                    {
                        _currentSound.Stop();
                    }

                    _currentSoundData = data;
                    _currentSound     = sound;
                    sound.Play();
                }
            }
        }