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

            if (!mAssetBundleItemDic.TryGetValue(crc, out item))
            {
                AssetBundle assetBundel = null;

                string hotAbPath = HotPatchManager.Instance.ComputeABPath(name);
                string fullpath  = string.IsNullOrEmpty(hotAbPath) ? ABLoadPath + name : hotAbPath;
                byte[] bytes     = AES.AESFileByteDecrypt(fullpath, EdgeFrameworkConst.AESKEY);
                assetBundel = AssetBundle.LoadFromMemory(bytes);

                if (assetBundel == null)
                {
                    Debug.LogError("Load AssetBundle Error:" + fullpath);
                }

                item    = mAssetBundleItemPool.Allocate();
                item.AB = assetBundel;
                item.ReCount++;
                mAssetBundleItemDic.Add(crc, item);
            }
            else
            {
                item.ReCount++;
            }
            return(item.AB);
        }
Beispiel #2
0
        void UnLoadAssetBundle(string name)
        {
            TAssetBundleItem item = null;
            uint             crc  = CRC32.GetCRC32(name);

            if (mAssetBundleItemDic.TryGetValue(crc, out item) && item != null)
            {
                item.ReCount--;
                if (item.ReCount <= 0 && item.AB != null)
                {
                    item.AB.Unload(true);
                    item.Reset();
                    mAssetBundleItemPool.Recycle(item);
                    mAssetBundleItemDic.Remove(crc);
                }
            }
        }