Exemple #1
0
        /// <summary>
        /// 播放
        /// </summary>
        public virtual AudioObject Play(string path, Transform parent, AudioParamete audioParamete)
        {
            if (parent == null)
            {
                parent = defaultParent;               //更换成默认目标父体
            }
            AudioObject audio = default(AudioObject); //定义默认空的音频

            try
            {
                audio = audioList.Find(a => !a.isPlay && a.transform.parent == parent && a.audioName == path);//根据条件返回音频物体

                if (audio == null)
                {
                    audio = AddAudioObject(path, parent, audioParamete);//没有符合的音频,新添加一个音频
                }
                else
                {
                    audio.SetAudioData(audioParamete); //找到符合要求的音频更换音频数据
                }
                audio.Play();                          //播放音频
            }
            catch (Exception ex)
            {
                Debug.Log(ex.Data);
                audioList.RemoveNull();//清除空的音频物体
            }
            return(audio);
        }
Exemple #2
0
 /// <summary>
 /// 设置音频数据
 /// </summary>
 public void SetAudioData(AudioParamete audioData)
 {
     audioSource.clip         = clip;
     audioSource.loop         = audioData.loop;
     audioSource.volume       = audioData.volume;
     volume                   = audioData.volume;
     audioSource.spatialBlend = audioData.audio3DValue;
     audioSource.minDistance  = audioData.minDistance;
     audioSource.maxDistance  = audioData.maxDistance;
 }
Exemple #3
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="soundPath"></param>
        /// <param name="isLoop"></param>
        /// <param name="volume"></param>
        public void init(AudioClip audio, AudioParamete audioParamete)
        {
            this.clip = audio;

            audioSource.clip         = clip;
            audioSource.loop         = audioParamete.loop;
            audioSource.volume       = audioParamete.volume;
            volume                   = audioParamete.volume;
            audioSource.spatialBlend = audioParamete.audio3DValue;
            audioSource.minDistance  = audioParamete.minDistance;
            audioSource.maxDistance  = audioParamete.maxDistance;
        }
Exemple #4
0
        /// <summary>
        /// 生成音频对象
        /// </summary>
        /// <param name="audioClip"></param>
        /// <param name="parent"></param>
        /// <param name="audioParamete"></param>
        /// <returns></returns>
        protected virtual AudioObject AddAudioObject(string path, Transform parent, AudioParamete audioParamete)
        {
            AudioClip   audioClip   = Resources.Load <AudioClip>(defaultPath + path);
            GameObject  g           = new GameObject(path);
            AudioObject audioObject = g.AddComponent <AudioObject>();

            audioObject.init(audioClip, audioParamete);
            if (parent)
            {
                audioObject.transform.parent           = parent;
                audioObject.transform.localEulerAngles = Vector3.zero;
                audioObject.transform.localPosition    = Vector3.zero;
            }
            audioList.Add(audioObject);
            return(audioObject);
        }
Exemple #5
0
        /// <summary>
        /// 生成音频对象
        /// </summary>
        /// <param name="path"></param>
        /// <param name="trans"></param>
        /// <param name="audioParamete"></param>
        /// <returns></returns>
        protected override AudioObject AddAudioObject(string path, Transform trans, AudioParamete audioParamete)
        {
            AudioObject audioObject = base.AddAudioObject(path, trans, audioParamete);

            if (trans == null)
            {
                if (defaultParent)
                {
                    audioObject.transform.parent = defaultParent;
                }
                else
                {
                    defaultParent = new GameObject("EffsetAudioManage").transform;
                    GameObject.DontDestroyOnLoad(defaultParent);
                    audioObject.transform.parent = defaultParent;
                }
            }
            return(audioObject);
        }
Exemple #6
0
 /// <summary>
 /// 播放
 /// </summary>
 /// <param name="path">路径</param>
 /// <param name="parent">父体</param>
 /// <param name="audioParamete">音频参数</param>
 /// <returns></returns>
 public override AudioObject Play(string path, Transform parent, AudioParamete audioParamete)
 {
     return(base.Play(path, parent, audioParamete));
 }