public static IEnumerator LoadAssetsIEnumerator(string path, CallBack <AssetData[]> callBack)
        {
            if (assetBundleManifest == null)
            {
                LoadAssetBundleManifest();
            }
            AssetData[] rds = null;
            if (!assetCacheDic.ContainsKey(path))
            {
                string[] depArr = GetAllDependenciesName(Path.GetFileNameWithoutExtension(path));
                for (int i = 0; i < depArr.Length; i++)
                {
                    string p = ResourcePathManager.GetPath(depArr[i]);
                    if (!assetCacheDic.ContainsKey(p))
                    {
                        yield return(LoadAssetsIEnumerator(p, null));
                    }
                }
                string temp = OtherUtils.GetWWWLoadPath(path);

                //加载bundle文件
                WWW www = new WWW(temp);
                yield return(www);

                if (string.IsNullOrEmpty(www.error))
                {
                    try
                    {
                        AssetBundle ab = www.assetBundle;
                        rds = DealWithAssetBundle(ab);
                        //Debug.Log("加载成功:" + path);
                        assetBundleCacheDic.Add(path, ab);
                        assetCacheDic.Add(path, rds);
                        www.Dispose();
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("Path:" + path + "\r\n" + e);
                    }
                }
                else
                {
                    Debug.LogError("加载失败,Path:" + path + "  error:" + www.error);
                }
            }
            else
            {
                rds = assetCacheDic[path];
            }
            yield return(new WaitForEndOfFrame());

            if (rds == null)
            {
                rds = new AssetData[0];
            }
            if (callBack != null)
            {
                callBack(rds);
            }
        }
Beispiel #2
0
        public static void ReleaseByName(string resName)
        {
            string path0 = ResourcePathManager.GetPath(resName);

            if (!string.IsNullOrEmpty(path0))
            {
                Release(path0);
            }
        }
        private static void LoadAssetBundleManifest()
        {
            string path = ResourcePathManager.GetPath("StreamingAssets");

            Debug.Log(path);
            AssetData[] resA = LoadAssets(path, false);
            assetBundleManifest = resA[0].asset as AssetBundleManifest;
            string[] sArr = assetBundleManifest.GetAllAssetBundles();
            for (int i = 0; i < sArr.Length; i++)
            {
                assetBundleManifestNameDic.Add(Path.GetFileNameWithoutExtension(sArr[i]), sArr[i]);
            }
        }
        public static AssetData[] LoadAssets(string path, bool isLoadDependencieRes = true)
        {
            if (isLoadDependencieRes && assetBundleManifest == null)
            {
                LoadAssetBundleManifest();
            }

            if (assetCacheDic.ContainsKey(path))
            {
                return(assetCacheDic[path]);
            }

            if (Application.platform == RuntimePlatform.Android)
            {
                //Application.streamingAssetsPath = jar:file:///data/app/com.xxx.xxx-1.apk!/assets

                //Application.dataPath+”!assets” = /data/app/com.xxx.xxx-1.apk!assets
                path = path.Replace(@"jar:file://", "");
                path = path.Replace("apk!/assets", "apk!assets");
            }
            if (isLoadDependencieRes)
            {
                string[] depArr = GetAllDependenciesName(Path.GetFileNameWithoutExtension(path));
                for (int i = 0; i < depArr.Length; i++)
                {
                    string p = ResourcePathManager.GetPath(depArr[i]);
                    Debug.Log(p);
                    LoadAssets(p, isLoadDependencieRes);
                }
            }
            AssetBundle ab = AssetBundle.LoadFromFile(path);

            if (ab == null)
            {
                Debug.LogError("Load Sources failed! path: " + path);
                return(null);
            }
            AssetData[] rds = DealWithAssetBundle(ab);
            assetBundleCacheDic.Add(path, ab);
            assetCacheDic.Add(path, rds);
            // ab.Unload(false);
            return(rds);
        }
Beispiel #5
0
 /// <summary>
 /// 一次加载大量资源(用于关卡预加载)
 /// </summary>
 /// <param name="names">资源名字</param>
 /// <param name="callBackLoadEachOne">没加载一个回调一次,(参数是还剩余多少个要加载的)</param>
 /// <param name="completeCallback">加载完成回调</param>
 public static void LoadManyAssetAsyncByName(List <string> names, CallBack <int> callBackLoadEachOne = null, CallBack completeCallback = null)
 {
     Initialize();
     for (int i = 0; i < names.Count; i++)
     {
         string    path0 = ResourcePathManager.GetPath(names[i]);
         QueueData data  = new QueueData(path0, (res) =>
         {
             if (callBackLoadEachOne != null)
             {
                 callBackLoadEachOne(ResidueLoadAsyncCount);
             }
             if (ResidueLoadAsyncCount == 0 && completeCallback != null)
             {
                 completeCallback();
             }
         });
         loadQueue.Enqueue(data);
     }
     if (!IsLoadAsync)
     {
         MonoBehaviourRuntime.Instance.StartCoroutine(StartLoadQueue());
     }
 }
Beispiel #6
0
        /// <summary>
        /// 同步加载一个资源
        /// </summary>
        /// <param name="resName"></param>
        /// <param name="callBack"></param>
        public static AssetData[] LoadAssetsByName(string resName)
        {
            string path0 = ResourcePathManager.GetPath(resName);

            return(LoadAssets(path0));
        }
Beispiel #7
0
        public static void LoadAssetsAsyncByName(string resName, CallBack <AssetData[]> callBack)
        {
            string path0 = ResourcePathManager.GetPath(resName);

            LoadAssetsAsync(path0, callBack);
        }