コード例 #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    = ABLoadPath + name;
                assetBundle = AssetBundle.LoadFromFile(fullPath);
                if (assetBundle == null)
                {
                    ZLogger.Error(" load assetbundle Error : {0}", fullPath);
                }

                item             = m_AssetBundleItemPool.Spawn(true);
                item.assetBundle = assetBundle;
                item.RefCount++;
                m_AssetBundleItemDic.Add(crc, item);
            }
            else
            {
                item.RefCount++;
            }
            return(item.assetBundle);
        }
コード例 #2
0
        /// <summary>
        /// 释放AB包
        /// </summary>
        /// <param name="name"></param>
        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.Unload(true);
                    item.Reset();
                    m_AssetBundleItemPool.Recycle(item);
                    m_AssetBundleItemDic.Remove(crc);
                }
            }
        }