| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 | 
							- using System;
 
- using Fort23.Core;
 
- using UnityEngine;
 
- namespace Core.Audio
 
- {
 
-     public class AudioSourcePool : IDisposable
 
-     {
 
-         public object TimeLineAudioEventLogic;
 
-         private AudioSource _audioSource;
 
-         private TimerEntity _timerEntity;
 
-         // private AssetHandle _assetHandle;
 
-         public bool IsPlay;
 
-         public System.Action OnFinish;
 
-         private float maxTime;
 
-         public string CurrPlayName
 
-         {
 
-             get { return _currPlayName; }
 
-         }
 
-         public string _currPlayName;
 
-         public float AudioVolume
 
-         {
 
-             get { return _audioVolume; }
 
-         }
 
-         private float _audioVolume;
 
-         public bool IsBgm;
 
-         // public float p
 
-         public void Init(Transform root)
 
-         {
 
-             GameObject gameObject = new GameObject();
 
-             _audioSource = gameObject.AddComponent<AudioSource>();
 
-             gameObject.transform.SetParent(root);
 
-         }
 
-         public void Play(string audioName, bool isBgm, AssetHandle audioClip, bool isLoop, float volume,
 
-             float speed = 1)
 
-         {
 
-             if (audioClip == null)
 
-             {
 
-                 return;
 
-             }
 
-          
 
-             // if (_assetHandle != null)
 
-             // {
 
-             //     _assetHandle.Release();
 
-             // }
 
-             this.IsBgm = isBgm;
 
-             IsPlay = true;
 
-             _currPlayName = audioName;
 
-             // _assetHandle = audioClip;
 
-             _audioSource.clip = audioClip.AssetObject<AudioClip>();
 
-             _audioSource.loop = isLoop;
 
-             _audioSource.pitch = speed;
 
-             _audioVolume = volume;
 
-             Setvolume();
 
-             if (speed > 1)
 
-             {
 
-                 _audioSource.outputAudioMixerGroup = AudioManager.Instance.AudioMixerGroup;
 
-                 _audioSource.outputAudioMixerGroup.audioMixer.SetFloat("path", 1f / speed);
 
-             }
 
-             else
 
-             {
 
-                 _audioSource.outputAudioMixerGroup = null;
 
-             }
 
-             _audioSource.Play();
 
-             maxTime = _audioSource.clip.length;
 
-             if (!isLoop)
 
-             {
 
-                 _timerEntity = TimerComponent.Instance.AddTimer((long)(maxTime * 1000L),
 
-                     delegate { Finish(); });
 
-             }
 
-         }
 
-         public float GetPlayTime()
 
-         {
 
-             if (_audioSource == null || _audioSource.clip == null)
 
-             {
 
-                 return -1;
 
-             }
 
-             return _audioSource.time;
 
-         }
 
-         public void Setvolume(float volume)
 
-         {
 
-             _audioVolume = volume;
 
-             if (_audioVolume < 0)
 
-             {
 
-                 return;
 
-             }
 
-             Setvolume();
 
-         }
 
-         public void Setvolume()
 
-         {
 
-             _audioSource.volume = _audioVolume *
 
-                                   (IsBgm ? AudioManager.Instance.BgmVolume : AudioManager.Instance.AudionVolume);
 
-         }
 
-         public float Progress()
 
-         {
 
-             return _audioSource.time / maxTime;
 
-         }
 
-         public void Finish()
 
-         {
 
-             IsPlay = false;
 
-             OnFinish?.Invoke();
 
-             _audioSource.Stop();
 
-             AudioManager.Instance.Recycle(this);
 
-             TimerComponent.Instance.Remove(_timerEntity);
 
-             _timerEntity = null;
 
-         }
 
-         public void Stop()
 
-         {
 
-             IsPlay = false;
 
-             _audioSource.Stop();
 
-         }
 
-         public void Pause()
 
-         {
 
-             _audioSource.Pause();
 
-         }
 
-         public void UnPause()
 
-         {
 
-             _audioSource.UnPause();
 
-         }
 
-         public void Dispose()
 
-         {
 
-         }
 
-     }
 
- }
 
 
  |