Example #1
0
        /// <summary>
        /// 加载资源
        /// Type版本
        /// </summary>
        /// <param name="type"></param>
        /// <param name="assetName"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public Object LoadFormAssetBundle(Type type, string assetName, AssetBundleItem item)
        {
            if (item != null)
            {
                var gobj = LoadFormAssetBundle(assetName, item, type);
                return(gobj);
            }

            BDebug.LogError("不存在:" + assetName);
            return(null);
        }
Example #2
0
        /// <summary>
        /// 加载资源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="abName"></param>
        /// <param name="objName"></param>
        /// <returns></returns>
        public T LoadFormAssetBundle <T>(string assetName, AssetBundleItem item) where T : UnityEngine.Object
        {
            var obj = LoadFormAssetBundle(typeof(T), assetName, item);

            if (obj)
            {
                return(obj as T);
            }

            return(null);
        }
Example #3
0
        /// <summary>
        /// 加载资源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="abName"></param>
        /// <param name="objName"></param>
        /// <returns></returns>
        private Object LoadFormAssetBundle(string assetName, AssetBundleItem item, Type t)
        {
            Object            o   = null;
            AssetBundleWapper abr = null;

            if (AssetbundleMap.TryGetValue(item.AssetBundlePath, out abr))
            {
                //var assetType = this.assetConfigLoder.AssetTypeList[item.AssetType];

                //优先处理图集
                if (item.AssetType == this.AssetConfigLoder.TYPE_SPRITE_ATLAS)
                {
                    o = abr.LoadTextureFormAtlas(assetName);
                }
                //其他需要处理的资源类型,依次判断.
                else
                {
                    o = abr.LoadAsset(assetName, t);
                }

                // switch ((AssetBundleItem.AssetTypeEnum)item.AssetType)
                // {
                //     //暂时需要特殊处理的只有一个
                //     case AssetBundleItem.AssetTypeEnum.SpriteAtlas:
                //     {
                //
                //     }
                //         break;
                //     case AssetBundleItem.AssetTypeEnum.Prefab:
                //     case AssetBundleItem.AssetTypeEnum.Texture:
                //     case AssetBundleItem.AssetTypeEnum.Others:
                //     default:
                //     {
                //
                //     }
                //         break;
                // }
            }
            else
            {
                BDebug.Log("资源不存在:" + assetName + " - " + item.AssetBundlePath, "red");

                return(null);
            }

            return(o);
        }
Example #4
0
        /// <summary>
        /// 加载实例资源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="loadType"></param>
        /// <param name="assetLoadPath">api传入的加载路径,Runtime下的相对路径</param>
        /// <param name="item"></param>
        /// <param name="abName"></param>
        /// <param name="objName"></param>
        /// <returns></returns>
        public Object LoadObjectFormAssetBundle(Type loadType, string assetLoadPath, AssetBundleItem item)
        {
            Object retObj = null;

            if (AssetbundleCacheMap.TryGetValue(item.AssetBundlePath, out var abw))
            {
                retObj = abw.LoadAsset(loadType, assetLoadPath, item.AssetType);
                //加入缓存
                AddObjectToCache(loadType, assetLoadPath, retObj);
            }
            else
            {
                BDebug.Log("资源不存在:" + assetLoadPath + " - " + item.AssetBundlePath, "red");
                return(null);
            }

            return(retObj);
        }
Example #5
0
        /// <summary>
        /// 获取依赖文件
        /// </summary>
        /// <returns></returns>
        public List <AssetBundleItem> GetDependAssets(AssetBundleItem assetBundleItem)
        {
            var retlist = new List <AssetBundleItem>();

            if (assetBundleItem != null && assetBundleItem.DependAssetIds != null && assetBundleItem.DependAssetIds.Length > 0)
            {
                int len = assetBundleItem.DependAssetIds.Length;
                retlist = new List <AssetBundleItem>(len);
                //找到依赖资源
                for (int i = 0; i < len; i++)
                {
                    var idx    = assetBundleItem.DependAssetIds[i];
                    var abItem = this.AssetbundleItemList[idx];
                    retlist.Add(abItem);
                }
            }


            return(retlist);
        }
Example #6
0
 /// <summary>
 /// 加载实例资源
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="loadType"></param>
 /// <param name="assetLoadPath">api传入的加载路径,Runtime下的相对路径</param>
 /// <param name="item"></param>
 /// <param name="abName"></param>
 /// <param name="objName"></param>
 /// <returns></returns>
 public void AsyncLoadObjectFormAssetBundle(Type loadType, string assetLoadPath, AssetBundleItem item, Action <Object> callback)
 {
     if (AssetbundleCacheMap.TryGetValue(item.AssetBundlePath, out var abw))
     {
         //item.AssetType == AssetType.TYPE_SPRITE_ATLAS
         //异步加载
         abw.AsyncLoadAsset(loadType, assetLoadPath, (o) =>
         {
             //加入缓存
             AddObjectToCache(loadType, assetLoadPath, o);
             //触发回调
             callback?.Invoke(o);
         }, item.AssetType);
     }
     else
     {
         BDebug.Log("资源不存在:" + assetLoadPath + " - " + item.AssetBundlePath, "red");
     }
 }