public AudioClip LoadAudio(string path) { var name = Path.GetFileNameWithoutExtension(path); try { var aud = new AudioFileReader(path); var AudioData = new float[aud.Length]; aud.Read(AudioData, 0, (int)aud.Length); var clip = AudioClip.Create(name, (int)aud.Length, aud.WaveFormat.Channels, aud.WaveFormat.SampleRate, false); clip.SetData(AudioData, 0); if (clip.isReadyToPlay) { aud.Dispose(); AudioLoveConfig config = new AudioLoveConfig(); config.clip = clip; config.requireLv = -1; audioCllips.Add(path, config); // audioCllips.Add(name, clip); return(clip); } } catch { return(null); } return(null); }
public AudioClip GetAudioClipByName(string name) { AudioLoveConfig audio = null; if (!audioCllips.TryGetValue(name, out audio)) { return(LoadAudio(name)); } return(audio.clip); }
public void InitAudioByLoveLevel(int lv) { string path = audioClipsLevelPath + lv.ToString() + "/"; var audios = Resources.LoadAll <AudioClip>(path); for (int i = 0; i < audios.Length; ++i) { var audio = Instantiate <AudioClip>(audios[i]); AudioLoveConfig config = new AudioLoveConfig(); config.requireLv = lv; config.clip = audio; if (audioCllips.ContainsKey(audios[i].name)) { Debug.Log(audios[i].name + " " + path + " " + i + " " + audios.Length); } audioCllips.Add(audios[i].name, config); } }