Exemple #1
0
        public void UnloadUnusedBundles(int tag)
        {
            if (m_AssetBundles.Count == 0)
            {
                return;
            }

            AssetBundleReference abr = null;

            Stack <string> checkQueue = StackPool <string> .Get();

            HashSet <string> checkings = HashSetPool <string> .Get();


            Action <string> checkFun = (key) =>
            {
                abr = m_AssetBundles[key];
                checkings.Remove(key);

                if (abr.isUnused())
                {
                    //check dependencies
                    if (abr.dependencies != null && abr.dependencies.Count > 0)
                    {
                        foreach (AssetBundleReference sub in abr.dependencies)
                        {
                            //只有同样tag和空tag的ref才需要重新检查。
                            if (sub.isCache && (sub.tagCount == 0 || sub.HaveTag(tag)) && !checkings.Contains(sub.name))
                            {
                                checkQueue.Push(sub.name);
                            }
                        }
                    }

                    abr.Dispose();
                    m_AssetBundles.Remove(key);
                }
            };

            foreach (string key in m_AssetBundles.Keys)
            {
                abr = m_AssetBundles[key];
                if (abr.HaveTag(tag) && abr.isCache)
                {
                    checkQueue.Push(key);
                    checkings.Add(key);
                }
            }

            //recheck unused asset bundle
            while (checkQueue.Count > 0)
            {
                checkFun(checkQueue.Pop());
            }

            StackPool <string> .Release(checkQueue);

            HashSetPool <string> .Release(checkings);
        }
        void ReleaseDependencies()
        {
            var iter = m_Dependencies.GetEnumerator();

            while (iter.MoveNext())
            {
                iter.Current.Release();
            }
            HashSetPool <AssetBundleReference> .Release(m_Dependencies);

            m_Dependencies = null;
        }
        public virtual void Dispose(bool disposing, bool forceRemoveAll)
        {
            if (!m_Disposed)
            {
                if (disposing)
                {
                    ListPool <WeakReference> .Release(m_Owners);

                    m_Owners = null;
                    HashSetPool <int> .Release(m_Tags);
                }
                m_Disposed = true;
            }
        }