Exemplo n.º 1
0
        /// <summary>
        /// AB的引用-1,若为0则删除该AB
        /// </summary>
        /// <param name="path"></param>
        public static void Delete(string path)
        {
            path = path.ToLower();
            if (cacheAssetBundleItemDic.ContainsKey(path))
            {
                AssetBundleItem ab = cacheAssetBundleItemDic[path];

                if (ab.isHasDependence)
                {
                    //删除依赖
                    string[] dps = mainfest.GetAllDependencies(path);
                    for (int i = 0, len = dps.Length; i < len; i++)
                    {
                        Delete(dps[i]);
                    }
                }

                ab.refCount--;
                if (ab.refCount <= 0)
                {
                    Debug.Log("wjr---ABDelete---" + ab.pathName);
                    ab.assetBundle.Unload(true);
                    ab = null;
                    cacheAssetBundleItemDic.Remove(path);
                }
            }
        }
Exemplo n.º 2
0
 void LoadAsyncCallback(AssetBundleItem ab)
 {
     m_obj = ab.LoadAsset(typeof(UnityEngine.Object));
     if (m_callback != null)
     {
         m_callback();
     }
 }
Exemplo n.º 3
0
 public void Destroy()
 {
     if (assetBundleItem != null)
     {
         AssetBundleUtility.Delete(m_fullPath);
         assetBundleItem = null;
     }
 }
Exemplo n.º 4
0
 void LoadAsyncCallback(AssetBundleItem ab)
 {
     assetBundleItem = ab;
     if (m_callback != null)
     {
         m_callback();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 异步加载AB资源
        /// </summary>
        /// <param name="path">AB资源路径</param>
        /// <param name="fileName">AB资源文件名</param>
        /// <param name="isHasDependence">是否存在依赖关系</param>
        /// <returns>AB包信息</returns>
        public static IEnumerator LoadAsync(string path, string fileName, System.Action <AssetBundleItem> callback, bool isHasDependence = true)
        {
            if (mainfest != null)
            {
                path     = path.ToLower();
                fileName = fileName.ToLower();

                if (isHasDependence)
                {
                    //读取依赖
                    string[] dps = mainfest.GetAllDependencies(path);
                    int      len = dps.Length;
                    for (int i = 0; i < len; i++)
                    {
                        AssetBundleItem dItem;
                        if (cacheAssetBundleItemDic.ContainsKey(dps[i]))
                        {
                            dItem = cacheAssetBundleItemDic[dps[i]];
                        }
                        else
                        {
                            dItem = new AssetBundleItem(dps[i], fileName, false);
                            AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(dItem.pathName);
                            yield return(request);

                            dItem.assetBundle = request.assetBundle;
                            cacheAssetBundleItemDic[dps[i]] = dItem;
                        }
                        Debug.Log("wjr---ABLoadAsync---Dependence---" + dps[i]);
                        dItem.refCount++;
                    }
                }

                AssetBundleItem ab;
                if (cacheAssetBundleItemDic.ContainsKey(path))
                {
                    ab = cacheAssetBundleItemDic[path];
                }
                else
                {
                    ab = new AssetBundleItem(path, fileName, isHasDependence);
                    AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(ab.pathName);
                    yield return(request);

                    ab.assetBundle = request.assetBundle;
                    cacheAssetBundleItemDic[path] = ab;
                }
                Debug.Log("wjr---ABLoadAsync---" + path);
                ab.refCount++;
                if (callback != null)
                {
                    callback(ab);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 同步加载AB资源
        /// </summary>
        /// <param name="path">AB资源路径</param>
        /// <param name="fileName">AB资源文件名</param>
        /// <param name="isHasDependence">是否存在依赖关系</param>
        /// <returns>AB包信息</returns>
        public static AssetBundleItem Load(string path, string fileName, bool isHasDependence = true)
        {
            if (mainfest != null)
            {
                path     = path.ToLower();
                fileName = fileName.ToLower();

                if (isHasDependence)
                {
                    //读取依赖
                    string[] dps = mainfest.GetAllDependencies(path);
                    int      len = dps.Length;
                    for (int i = 0; i < len; i++)
                    {
                        AssetBundleItem dItem;
                        if (cacheAssetBundleItemDic.ContainsKey(dps[i]))
                        {
                            dItem = cacheAssetBundleItemDic[dps[i]];
                        }
                        else
                        {
                            dItem             = new AssetBundleItem(dps[i], fileName, false);
                            dItem.assetBundle = AssetBundle.LoadFromFile(dItem.pathName);
                            cacheAssetBundleItemDic.Add(dps[i], dItem);
                        }
                        Debug.Log("wjr---ABLoad---Dependence---" + dps[i]);
                        dItem.refCount++;
                    }
                }

                AssetBundleItem ab;
                if (cacheAssetBundleItemDic.ContainsKey(path))
                {
                    ab = cacheAssetBundleItemDic[path];
                }
                else
                {
                    ab             = new AssetBundleItem(path, fileName, isHasDependence);
                    ab.assetBundle = AssetBundle.LoadFromFile(ab.pathName);
                    cacheAssetBundleItemDic.Add(path, ab);
                }
                Debug.Log("wjr---ABLoad---" + path);
                ab.refCount++;
                return(ab);
            }
            return(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 加载AssetBundle,获取里面的Asset
        /// </summary>
        /// <param name="isHasDependence">是否存在依赖</param>
        public virtual void Load(bool isHasDependence = true)
        {
            AssetBundleItem assetBundleItem = AssetBundleUtility.Load(m_fullPath, name, isHasDependence);

            m_obj = assetBundleItem.LoadAsset(typeof(UnityEngine.Object));
        }
Exemplo n.º 8
0
 public virtual void Load()
 {
     assetBundleItem = AssetBundleUtility.Load(m_fullPath, "", false);
 }