Exemplo n.º 1
0
        private void CleanResources()
        {
            mName = null;

            mPlayCount        = 0;
            mIsPause          = false;
            mOnFinishListener = null;
            mLeftDelayTime    = -1;
            mCustomEventID    = -1;

            if (mTimeItem != null)
            {
                mTimeItem.Cancel();
                mTimeItem = null;
            }

            if (mSource != null)
            {
                if (mSource.clip == mAudioClip)
                {
                    mSource.Stop();
                    mSource.clip = null;
                }
            }

            mAudioClip = null;

            if (mLoader != null)
            {
                mLoader.Recycle2Cache();
                mLoader = null;
            }
        }
Exemplo n.º 2
0
        public void SetAudio(GameObject root, string name, bool loop)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            if (mName == name)
            {
                return;
            }

            if (mSource == null)
            {
                mSource = root.AddComponent <AudioSource>();
            }

            //防止卸载后立马加载的情况
            ResLoader preLoader = mLoader;

            mLoader = null;
            CleanResources();

            mLoader = ResLoader.Allocate();

            mIsLoop = loop;
            mName   = name;

            mLoader.Add2Load(name, OnResLoadFinish);

            if (preLoader != null)
            {
                preLoader.Recycle2Cache();
                preLoader = null;
            }

            if (mLoader != null)
            {
                mLoader.LoadAsync();
            }
        }