Beispiel #1
0
        protected override IEnumerator PerformTask(AsyncLoadingTask task, ABRefOut output)
        {
            yield return(null);

            SimAssetBundle abRef;

            if (m_AllAssetBundles.TryGetValue(task.assetbundleName, out abRef))
            {
                abRef.loaded = true;
                abRef.SetAllowUnload(task.allowUnload);
                output.abRef = abRef;
                output.md5   = "";
            }
        }
Beispiel #2
0
 /// <summary>
 /// 资源从磁盘载入
 /// </summary>
 protected abstract IEnumerator PerformTask(AsyncLoadingTask task, ABRefOut output);
        protected override IEnumerator PerformTask(AsyncLoadingTask task, ABRefOut output)
        {
            string suitPath = "";
            string abName   = task.assetbundleName;

            if (!task.forcedStreaming)
            {
                suitPath = Path.Combine(bundleRootPath, abName);
            }
            if (!File.Exists(suitPath))
            {
                suitPath = Path.Combine(streamingRootPath, abName);
            }
            if (!suitPath.Contains("://"))
            {
                if (suitPath.Contains(":"))
                {
                    suitPath = "file:///" + suitPath;
                }
                else
                {
                    suitPath = "file://" + suitPath;
                }
            }

            WWW www = new WWW(suitPath);

            yield return(www);

            if (www.error == null)
            {
                // 把资源缓存到persistentDataPath
                output.transfer = new AssetsTransfer(www.bytes, Path.Combine(bundleRootPath, abName));

                if (task.needMD5)
                {
                    output.md5 = CMD5.MD5Data(www.bytes);
                }
                AssetBundle ab = www.assetBundle;
                if (ab != null)
                {
                    //// 资源是一个AssetBundle,获取Bundle里的所有Assets, 保存
                    //AssetBundleRequest abReq = ab.LoadAllAssetsAsync();
                    //while (!abReq.isDone) {
                    //    if (progressView && progressView.gameObject.activeInHierarchy) {
                    //        progressView.value = abReq.progress;
                    //    }
                    //    yield return 1;
                    //}
                    //if (progressView && progressView.gameObject.activeInHierarchy) {
                    //    progressView.value = 1;
                    //}

                    if (output.abRef == null)
                    {
                        output.abRef = new AssetBundleRef(abName, ab, task.allowUnload);
                    }
                    else
                    {
                        var abRef = output.abRef as AssetBundleRef;
                        abRef.Init(abName, ab, task.allowUnload);
                    }
                }
            }
        }