Esempio n. 1
0
        /// <summary>
        /// 卸载资源
        /// </summary>
        /// <param name="resPath"></param>
        public void UnloadResource(string assetPath)
        {
            if (m_assetLoadedDict.ContainsKey(assetPath))
            {
                AssetLoader ac = m_assetLoadedDict[assetPath];
                ac.SubtractRefCount();

                if (0 <= ac.RefCount) //将其从在用资源列表中移除
                {
                    m_assetLoadedDict.Remove(assetPath);

                    if (IsNeedCacheUnloadAsset())
                    {
                        AssetRemover ar = new AssetRemover(assetPath, ac.Asset, Time.time);
                        m_assetRecycleList.Add(ar);
                    }
                    else
                    {
                        m_assetLoadedDict.Remove(assetPath);
                        Resources.UnloadAsset(ac.Asset);
                    }
                }
            }
            else
            {
                LoggerHelper.Warning(string.Format("Unload Res Failed: {0} not in asset list.", assetPath));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 从回收列表中加载资源
        /// </summary>
        private Object LoadAssetFromRecycleList(string assetPath)
        {
            Object assetObj = null;

            for (int i = m_assetRecycleList.Count - 1; i != -1; --i)
            {
                AssetRemover ar = m_assetRecycleList[i];
                if (ar.AssetPath == assetPath && null != ar.Asset)
                {
                    m_assetRecycleList.RemoveAt(i);

                    m_assetLoadedDict.Add(assetPath, new AssetLoader(ar.Asset));
                }
            }

            return(assetObj);
        }