public void Stop(int id) { SoundConfigBase data = SoundConfigBaseManager.instance.Find(id); for (int i = 0; i < m_soundASLst.Count; ++i) { if (m_soundASLst[i].clip.name == data.Sound) { m_soundASLst[i].Stop(); } } }
public void Play(int id, bool isloop = false) { if (m_loadingLst.IndexOf(id) != -1) { return; } if (m_clipCache.ContainsKey(id)) { AudioClip ac; SoundConfigBase cached = SoundConfigBaseManager.instance.Find(id); m_clipCache.TryGetValue(id, out ac); if (ac != null) { if (id >= 2800) { PlayBgm(ac, cached.Volume); } else { StartCoroutine(PlaySound(ac, cached.Delay, cached.Volume, isloop)); } return; } } SoundConfigBase data = SoundConfigBaseManager.instance.Find(id); if (data == null) { Util.LogError("SoundConfig has not key:" + id); return; } string assName = data.Sound; string abName = data.Sound.ToLower(); m_loadingLst.Add(id); Main.ResManager.LoadAudio(abName, assName, (objs) => { if (objs[0] == null) { Util.LogError("获取音频失败" + abName + " " + assName); return; } AudioClip ac = objs[0] as AudioClip; if (ac != null) { if (id >= 2800) { PlayBgm(ac, data.Volume); } else { StartCoroutine(PlaySound(ac, data.Delay, data.Volume, isloop)); } m_loadingLst.Remove(id); if (!m_clipCache.ContainsKey(id)) { m_clipCache.Add(id, ac); } } }); }