using System.Collections.Generic; using UnityEngine; using YooAsset; namespace Script.FrameWork.Sound { public class SoundManager : Singleton { private List _audio = new(); public void PlaySound(string clipPath, bool loop = false) { if (string.IsNullOrEmpty(clipPath)) return; var audioSource = _audio.Find(audio => !audio.isPlaying && audio.time <= 0); if (audioSource == null) { var sound = new GameObject("sound"); audioSource = sound.AddComponent(); _audio.Add(audioSource); } var clip = YooAssets.LoadAssetSync(clipPath).AssetObject as AudioClip; clip.name = clipPath; audioSource.clip = clip; audioSource.loop = false; audioSource.Play(); } public void StopSound(string clipPath) { if (string.IsNullOrEmpty(clipPath)) return; var audioSource = _audio.Find(audio => audio.clip != null && audio.clip.name == clipPath); if (audioSource != null) { audioSource.Stop(); audioSource.time = 0; // audioSource.clip = null; } } } }