Пример #1
0
        /// <summary>
        /// 初始化AudioObject
        /// </summary>
        /// <param name="path"></param>
        public void InitAudioObject(MAudioIdType configId, Vector3 pos, float durTime, int audioType,

                                    bool loop, int loopCount)
        {
            mAudioObject = MAudioObject.Get(pos);
            var path = GetEffectPrefabPathByEffectType(configId);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            this.duarationTime = durTime;
            this.audioType     = audioType;
            this.isLoop        = loop;
            this.mLoopCount    = loopCount;
            var source = mAudioObject.mAudio;
            var loader = ResManager.Instance.Load(path, false);

            if (loader == null)
            {
#if DEBUG
                //Logger.LogError("InitAudioObject loader Not Found : " + path);
#endif
                return;
            }
            var clip = loader.mMainAsset as AudioClip;
            if (clip == null)
            {
#if DEBUG
                //Logger.LogError("InitAudioObject clip Not Found : " + path);
#endif
                return;
            }
            source.clip = clip;
            clipLenght  = clip.length;

            if (curAudioBigType == E_MAudioBigType.EFFECT)
            {
                source.minDistance          = 5;
                source.maxDistance          = 1000;
                source.dopplerLevel         = 1;
                source.rolloffMode          = AudioRolloffMode.Linear;
                source.pitch                = 1f;
                source.spatialBlend         = 1F;
                source.ignoreListenerVolume = false;
                source.spread               = 180f;
            }
            else
            {
                source.spatialBlend = 0f;
                GameObject.DontDestroyOnLoad(mAudioObject.mGo);
            }
            source.volume           = targetVolume;
            mAudioObject.mGo.name   = CurAudioType + "----" + path;
            mAudioObject.mAudioInfo = this;
            source.time             = mTotalPlayTime % clipLenght;
            source.loop             = isLoop;
        }
Пример #2
0
        //public void Enba


        /// <summary>
        /// 创建50个缓存音频 ,避免内存碎片化
        /// </summary>
        /// <param name="count"></param>
        public void MakeReserve(int count)
        {
            var tmp = new MAudioObject[count];

            for (int i = 0; i < count; ++i)
            {
                tmp[i] = MAudioObject.Get(Vector3.zero);
            }//for
            for (int i = 0; i < count; ++i)
            {
                tmp[i].Release();
            } //for
        }     //MakeReserve