Beispiel #1
0
        /// <summary>
        /// 加载单个assetbundle根据名字
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private AssetBundle LoadAssetBundle(string name)
        {
            AssetBundleItem item = null;
            uint            crc  = CRC32.GetCrc32(name);

            if (!m_AssetBundleItemDic.TryGetValue(crc, out item))
            {
                AssetBundle assetBundle = null;
                string      fullPath    = Application.streamingAssetsPath + "/" + name;
                assetBundle = AssetBundle.LoadFromFile(fullPath);

                if (assetBundle == null)
                {
                    DebugPlus.LogError(" Load AssetBundle Error:" + fullPath);
                }

                item             = m_AssetBundleItemPool.Spawn(true);
                item.assetBundle = assetBundle;
                item.RefCount++;
                m_AssetBundleItemDic.Add(crc, item);
            }
            else
            {
                item.RefCount++;
            }
            return(item.assetBundle);
        }
Beispiel #2
0
        private void UnLoadAssetBundle(string name)
        {
            AssetBundleItem item = null;
            uint            crc  = CRC32.GetCrc32(name);

            if (m_AssetBundleItemDic.TryGetValue(crc, out item) && item != null)
            {
                item.RefCount--;
                if (item.RefCount <= 0 && item.assetBundle != null)
                {
                    item.assetBundle.Unload(true);
                    item.Rest();
                    m_AssetBundleItemPool.Recycle(item);
                    m_AssetBundleItemDic.Remove(crc);
                }
            }
        }