Пример #1
0
        /// <summary>
        /// 根据路径的crc加载中间类ResoucItem
        /// </summary>
        /// <param name="crc"></param>
        /// <returns></returns>
        protected internal AssetBundle LoadAssetBundle(uint crc)
        {
            ConfigItem configItem = null;

            if (!m_ConfigItemDic.TryGetValue(crc, out configItem) || configItem == null)
            {
                Log.Error("LoadResourceAssetBundle error: can not find crc {0} in AssetBundleConfig", crc.ToString());
                return(null);
            }

            AssetBundleItem bundleItem = null;

            if (m_AssetBundleItemDic.TryGetValue(crc, out bundleItem))
            {
                return(bundleItem.AssetBundle);
            }

            AssetBundle bundle = LoadAssetBundle(configItem.ABName);

            if (configItem.DependAssetBundle != null)
            {
                for (int i = 0; i < configItem.DependAssetBundle.Count; i++)
                {
                    LoadAssetBundle(configItem.DependAssetBundle[i]);
                }
            }
            return(bundle);
        }
Пример #2
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)
                {
                    Debug.LogError(" Load AssetBundle Error:" + fullPath);
                }

                item             = ReferencePool.Acquire <AssetBundleItem>();
                item.AssetBundle = assetBundle;
                item.RefCount++;
                m_AssetBundleItemDic.Add(crc, item);
            }
            else
            {
                item.RefCount++;
            }
            return(item.AssetBundle);
        }
Пример #3
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)
                {
                    Log.Debug("release " + name);
                    item.AssetBundle.Unload(true);
                    ReferencePool.Release(item);
                    m_AssetBundleItemDic.Remove(crc);
                }
            }
        }