Exemplo n.º 1
0
        /// <summary>
        /// 添加常驻音频资源,建议尽早添加,不要在用的时候再添加
        /// </summary>
        private void AddRetainAudio(string audioName)
        {
            if (mRetainResLoader == null)
            {
                mRetainResLoader = ResLoader.Allocate();
            }
            if (mRetainAudioNames == null)
            {
                mRetainAudioNames = new List <string>();
            }

            if (!mRetainAudioNames.Contains(audioName))
            {
                mRetainAudioNames.Add(audioName);
                mRetainResLoader.Add2Load(audioName);
                mRetainResLoader.LoadAsync();
            }
        }
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();
            }
        }