Example #1
0
    public void PlaySound(MatchSoundEvent evt, bool loop = false)
    {
        MatchSound ms = GameSystem.Instance.matchSoundConfig.GetSounds(evt);

        if (ms == null)
        {
            Debug.Log("No sounds for event:" + evt);
            return;
        }

        if (ms.sounds.Count > 0)
        {
            MatchSound.Item sound = ms.sounds[UnityEngine.Random.Range(0, ms.sounds.Count)];
            //Debug.Log("Play sound, Event:" + evt + " Sound:" + sound.soundId);
            GameUtils.Timer4View timer = new GameUtils.Timer4View((float)sound.fLag,
                                                                  () =>
            {
                AudioClip clip = AudioManager.Instance.GetClip("Misc/" + sound.soundId);
                if (clip != null)
                {
                    AudioManager.Instance.PlaySound(clip, true, 1f, 1f, loop);
                }
                else
                {
                    Debug.LogWarning("Sound file " + sound + " not found");
                }
            }, 1);
            m_soundsToPlay.Add(timer);
            timer.stop = false;
        }

        if (ms.narrator_sounds.Count > 0)
        {
            MatchSound.Item sound = ms.narrator_sounds[UnityEngine.Random.Range(0, ms.narrator_sounds.Count)];
            //Debug.Log("Play narrator sound, Event:" + evt + " Sound:" + sound.soundId);
            GameUtils.Timer4View timer = new GameUtils.Timer4View((float)sound.fLag,
                                                                  () =>
            {
                AudioClip clip = AudioManager.Instance.GetClip("Misc/" + sound.soundId);
                if (clip != null)
                {
                    AudioManager.Instance.PlaySound(clip, true, 1f, 1f, loop);
                }
                else
                {
                    Debug.LogWarning("Sound file " + sound + " not found");
                }
            }, 1);
            m_soundsToPlay.Add(timer);
            timer.stop = false;
        }
    }
Example #2
0
    void Awake()
    {
        Instance      = this;
        audioClipDict = new Dictionary <string, AudioClip>();
        foreach (AudioItem audioItem in audioClipList)
        {
            audioClipDict.Add(audioItem.key, audioItem.value);
        }
        poolOfAudioSource = new Stack <AudioSource>();

        var countOfPool = 10;

        while (countOfPool > 0)
        {
            poolOfAudioSource.Push(GetNewOne());
            countOfPool -= 1;
        }

        keysInPlaying = new List <KeyInPlaying>();
    }
    public void ReadConfig()
    {
        try
        {
            if (isLoadFinish == false)
            {
                return;
            }

            Debug.Log("Config reading " + name1);
            isLoadFinish = false;
            lock (LockObject) { GameSystem.Instance.readConfigCnt += 1; }

            string text = ResourceLoadManager.Instance.GetConfigText(name1);
            if (text == null)
            {
                ErrorDisplay.Instance.HandleLog("LoadConfig failed: " + name1, "", LogType.Error);
                return;
            }

            XmlDocument doc  = CommonFunction.LoadXmlConfig(GlobalConst.DIR_XML_MATCH_SOUND, text);
            XmlNode     root = doc.SelectSingleNode("Data");
            foreach (XmlNode line in root.SelectNodes("Line"))
            {
                if (CommonFunction.IsCommented(line))
                {
                    continue;
                }

                MatchSoundEvent evt = (MatchSoundEvent)(int.Parse(line.SelectSingleNode("event").InnerText));
                MatchSound      ms  = GetSounds(evt);
                if (ms == null)
                {
                    ms            = new MatchSound();
                    ms.soundEvent = evt;
                }
                string sounds = line.SelectSingleNode("sounds").InnerText;
                if (sounds.Length != 0)
                {
                    string[] sound = sounds.Split('&');
                    foreach (string str in sound)
                    {
                        string[]        tag  = str.Split(':');
                        MatchSound.Item item = new MatchSound.Item();
                        item.soundId = tag[0];
                        item.fLag    = IM.Number.Parse(tag[1]);
                        ms.sounds.Add(item);
                    }
                }

                sounds = line.SelectSingleNode("narrator_sounds").InnerText;
                if (sounds.Length != 0)
                {
                    string[] sound = sounds.Split('&');
                    foreach (string str in sound)
                    {
                        string[]        tag  = str.Split(':');
                        MatchSound.Item item = new MatchSound.Item();
                        item.soundId = tag[0];
                        item.fLag    = IM.Number.Parse(tag[1]);
                        ms.narrator_sounds.Add(item);
                    }
                }
                m_matchSounds.Add(ms);
            }
        }
        catch (XmlException exp)
        {
            Debug.Log("MatchSound config failed: " + exp.Message);
        }
    }