예제 #1
0
 protected override void OnDispose()
 {
     if (m_FadeTimeId != 0)
     {
         GameFrameEntry.GetModule <TimeModule>().RemoveTime(m_FadeTimeId);
     }
     AudioTools.DestroyAudioSource(base.s_audioSource);
     base.s_audioSource = null;
 }
예제 #2
0
        protected override async Task <AudioSource> OnPlay(AudioData audioConfig)
        {
            if (audioConfig != null)
            {
                var path       = audioConfig.ResPath;
                var start_time = audioConfig.StartTime;
                var end_time   = audioConfig.EndTime;
                var atype      = (AudioMode)audioConfig.Atype;
                var vol        = audioConfig.Vol <= 0 ? 1 : audioConfig.Vol;
                var vol_mul    = GetSettingVolume();
                var name       = "fade_" + this.GetAudioGuid();

                this.m_StartTime = start_time;
                this.m_EndTime   = end_time;
                this.m_MaxVolume = vol * vol_mul;
                AudioClip clip = await AudioTools.LoadAudioClip(path);

                if (clip != null)
                {
                    AudioSource source = AudioTools.CreateAudioSource(base.s_AudioRoot, name);
                    source.playOnAwake  = false;
                    source.spatialBlend = atype == AudioMode.A2D ? 0 : 1;
                    if (atype == AudioMode.A3D)
                    {
                        //source.minDistance = audioConfig.MinDistance;
                        source.dopplerLevel = 0;
                    }
                    source.clip   = clip;
                    source.volume = 0;
                    source.time   = start_time;
                    source.loop   = false;
                    source.Play();
                    this.m_ClipLenght = clip.length;
                    this.OnFade(source, true);
                    this.m_IsFadeEnding = false;
                    return(source);
                }
            }
            else
            {
                base.Stop();
            }
            return(null);
        }
예제 #3
0
        //创建一个音效复合节点
        public AudioCompositeBase CreateNode(AudioCompositeType stype, GameObject root = null)
        {
            //如果根节点为空则创建
            if (this.m_AudioRoot == null)
            {
                //this.Destroy();
                this.OnCreate();
            }
            AudioCompositeBase node   = null;
            List <int>         idList = null;

            if (this.m_NodeDic != null && this.m_NodeDic.Count > 0)
            {
                idList = new List <int>(this.m_NodeDic.Keys);
            }
            int node_id = AudioTools.RandomId(randomMin, randomMax, idList);

            if (root == null)
            {
                root = this.m_AudioRoot;
            }

            if (stype == AudioCompositeType.Parallel)
            {
                string name = "parallel_" + node_id;
                node = new AudioParallel(root, node_id, name);
            }
            else if (stype == AudioCompositeType.Sequence)
            {
                string name = "sequence_" + node_id;
                node = new AudioSequence(root, node_id, name);
            }
            else if (stype == AudioCompositeType.Single)
            {
                string name = "single_" + node_id;
                node = new AudioSingle(root, node_id, name);
            }
            this.AddNode(node_id, node);
            return(node);
        }
예제 #4
0
 protected override void OnDispose()
 {
     AudioTools.DestroyAudioSource(base.s_audioSource);
     base.s_audioSource = null;
 }
예제 #5
0
        protected override async Task <AudioSource> OnPlay(AudioData audioConfig)
        {
            if (audioConfig != null)
            {
                var path       = audioConfig.ResPath;
                var start_time = audioConfig.StartTime;
                var end_time   = audioConfig.EndTime;
                var atype      = (AudioMode)audioConfig.Atype;
                var vol        = audioConfig.Vol <= 0 ? 1 : audioConfig.Vol;
                var vol_mul    = GetSettingVolume();
                var name       = "once_" + this.GetAudioGuid();

                this.m_StartTime = start_time;
                this.m_EndTime   = end_time;
                AudioClip clip = await AudioTools.LoadAudioClip(path);

                //int soundID = 0;
                string filePath   = "";
                float  onceVolume = vol * vol_mul;

#if  !UNITY_EDITOR && UNITY_ANDROID//
                filePath = AudioManager.Instance.GetAndroidAudioID(audioConfig.id);
                if (!string.IsNullOrEmpty(filePath))
                {
                    m_AndroidPluginsSoundId = DBTSDK.SDKToolManager.Instance.PlayEffect(filePath, false, 1, 0, onceVolume);
                    //soundID = AndroidNativeAudio.play(fileID);
                    //soundID = AndroidNativeAudio.play(fileID, onceVolume, onceVolume);
                    //if (soundID != 0)
                    //   AndroidNativeAudio.setVolume(soundID, onceVolume, onceVolume);
                }
#endif
                if (clip != null)
                {
                    AudioSource source = AudioTools.CreateAudioSource(base.s_AudioRoot, name);
                    source.playOnAwake  = false;
                    source.spatialBlend = atype == AudioMode.A2D ? 0 : 1;
                    if (atype == AudioMode.A3D)
                    {
                        //source.minDistance = audioConfig.MinDistance;
                        source.dopplerLevel = 0;
                    }
                    source.clip = clip;

#if !UNITY_EDITOR && UNITY_ANDROID
                    if (m_AndroidPluginsSoundId != 0)
                    {
                        source.volume = 0;
                    }
                    else
                    {
                        source.volume = onceVolume;
                    }
#else
                    source.volume = onceVolume;
#endif

                    source.time = start_time;
                    source.loop = false;
                    source.Play();
                    return(source);
                }
            }
            else
            {
                base.Stop();
            }
            return(null);
        }