| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 | using UnityEngine;using FairyGUI;using GFGGame.Launcher;using YooAsset;using System.Collections;namespace GFGGame{    public class SoundManager : SingletonMonoBase<SoundManager>     {        private AudioSource player;        private AssetOperationHandle handle;        private Coroutine coroutine;        private bool _isOn = true;        public bool isOn        {            get            {                return _isOn;            }            set            {                if(_isOn != value)                {                    _isOn = value;                    if(_isOn)                    {                        GRoot.inst.soundVolume = 1;                    }                    else                    {                        GRoot.inst.soundVolume = 0;                        Stop();                    }                    LocalCache.SetBool(LauncherConfig.SOUND_KEY, _isOn);                }            }        }        private void Awake()        {            player = this.gameObject.AddComponent<AudioSource>();            isOn = LocalCache.GetBool(LauncherConfig.SOUND_KEY, true);        }        private void Start()         {                    }        private void Update()         {                    }        public void PlayOneShotCroutine(string path)        {            if (coroutine != null)            {                StopCoroutine(coroutine);            }            handle?.Release();            if (_isOn)            {                coroutine = StartCoroutine(PlayOneShot(path));            }        }        private IEnumerator PlayOneShot(string path)        {            //AudioClip clip = GFGAsset.Load<AudioClip>(path);            handle = YooAssets.LoadAssetAsync<AudioClip>(path);            yield return handle;            player.clip = handle.AssetObject as AudioClip;            player.Play();        }        public void Stop()        {            player.Stop();        }    }}
 |