Exemple #1
0
    /// <summary>
    /// 这是无脑拷贝StreamingAssets资源到PD目录
    /// </summary>
    private IEnumerator CopyAllABToPD(AssetBundleSettingHelper ABSettingHelper, AssetBundleHelper abh, Action callback = null)
    {
        StageInfo.ToStage(UpdaterStage.CopySAToPD);
        //这里是无脑拷贝版本,为了防止资源出错,可以重新搞一次
        var abpiSrc = ABSettingHelper.GetCurABVersionXmlStreamingAssetPath();
        var abpiDst = ABSettingHelper.GetCurABVersionXmlPersistentDataPath();

        //不存在,这个时候无脑删除文件夹,然后拷贝,防止文件夹里残留了奇怪的东西
        if (Directory.Exists(abpiDst.Dir_Full))
        {
            Directory.Delete(abpiDst.Dir_Full, true);
        }
//      AssetBundleHelper.TestLog("abpiSrc.Dir_Full:" + abpiSrc.Dir_Full);
//      AssetBundleHelper.TestLog("abpiSrc.FullName:" + abpiSrc.FullName);
//      AssetBundleHelper.TestLog("Application.dataPath:" + Application.dataPath);
//      AssetBundleHelper.TestLog("Application.streamingAssetsPath:" + Application.streamingAssetsPath);
//      AssetBundleHelper.TestLog("Application.persistentDataPath:" + Application.persistentDataPath);

        var localSAManifestABPI = ABSettingHelper.GetCurPlatformStreamingAssetManifestPath();
        var localSAManifest     = GetPathManifest(localSAManifestABPI.FullName);

        AssetBundleHelper.TestLog("ia am here *****" + localSAManifestABPI.FullName);
        if (localSAManifest != null)
        {
            //AssetBundleHelper.TestLog("if(localManifest != null) )))))))))))))))))))))))))))))))))))))))))))");
            var ABs = localSAManifest.GetAllAssetBundles();
            StageInfo.SetNUC(ABs.Length);
            foreach (var f in ABs)
            {
                var abpi    = ABSettingHelper.GetCurPlatformStreamingABPath(f);
                var abpiTar = ABSettingHelper.GetCurPlatformABPath(f);
                using (WWW www = new WWW(abpi.URI))
                {
                    while (true)
                    {
                        if (www.error != null)
                        {
                            Debug.LogError(www.error);
                            AssetBundleHelper.TestLog(www.error);
                            throw new NullReferenceException(www.url);
                        }
                        else if (www.isDone)
                        {
                            break;
                        }
                        yield return(null);
                    }
                    CreateFile(abpiTar, www.bytes);
                    if (www.assetBundle != null)
                    {
                        www.assetBundle.Unload(false);
                    }
                }
                StageInfo.AddUC();
                yield return(null);
            }


            //最后把manifeat和version也拷过去
            //manifest
            using (WWW www = new WWW(localSAManifestABPI.URI))
            {
                while (true)
                {
                    if (www.error != null)
                    {
                        Debug.LogError(www.error);
                        AssetBundleHelper.TestLog(www.error);
                        throw new NullReferenceException(www.url);
                    }
                    else if (www.isDone)
                    {
                        break;
                    }
                    yield return(null);
                }
                var localManifestABPI = ABSettingHelper.GetCurPlatformManifestPath();
                CreateFile(localManifestABPI, www.bytes);
                if (www.assetBundle != null)
                {
                    www.assetBundle.Unload(false);
                }
                StageInfo.AddUC();
                yield return(null);
            }
            //version XML
            using (WWW www = new WWW(abpiSrc.URI))
            {
                while (true)
                {
                    if (www.error != null)
                    {
                        Debug.LogError(www.error);
                        AssetBundleHelper.TestLog(www.error);
                        throw new NullReferenceException(www.url);
                    }
                    else if (www.isDone)
                    {
                        break;
                    }
                    yield return(null);
                }
                //var localManifestABPI = ABSettingHelper.GetCurPlatformManifestPath();
                CreateFile(abpiDst, www.bytes);

                StageInfo.AddUC();
                yield return(null);
            }
        }
        else
        {
            //SA目录里没有manifest的时候就什么都别干了
        }
        //CopyFolder(abpiSrc.Dir_Full, abpiDst.Dir_Full);
        if (callback != null)
        {
            callback.Invoke();
        }
    }