Exemple #1
0
        private IEnumerator RefreshContent(ContentDownloadItem contentDownloadItem)
        {
            string resourceAssetBundleName = contentDownloadItem.ContentInfo.ResourceAssetBundleName;
            string sceneAssetBundleName    = contentDownloadItem.ContentInfo.SceneAssetBundleName;

            if (contentDownloadItem.RefreshYieldInstruction != null)
            {
                contentDownloadItem.RefreshYieldInstruction.Dispose();
                contentDownloadItem.RefreshYieldInstruction = null;
            }

            using (AbstractDownloaderYieldInstruction refreshYieldInstruction = CreateRefreshYieldInstruction(resourceAssetBundleName, sceneAssetBundleName)) {
                contentDownloadItem.RefreshYieldInstruction = refreshYieldInstruction;
                contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Refreshing);

                yield return(refreshYieldInstruction);

                if (!refreshYieldInstruction.IsDisposed)
                {
                    contentDownloadItem.State = refreshYieldInstruction.DownloadState;
                    contentDownloadItem.Error = ContentDownloadError.None;

                    if (AssetBundleOptions.UseAssetBundlesInEditor)
                    {
                        if (contentDownloadItem.State == ContentDownloadState.Complete)
                        {
                            //Resource is already on disk, we retain it
                            if (contentDownloadItem.ResourceAssetBundle == null)
                            {
                                contentDownloadItem.ResourceAssetBundle = DownloadAssetBundleReference.FindOrCreateReference(resourceAssetBundleName);
                                contentDownloadItem.ResourceAssetBundle.Retain();
                            }

                            if (contentDownloadItem.SceneAssetBundle == null)
                            {
                                contentDownloadItem.SceneAssetBundle = DownloadAssetBundleReference.FindOrCreateReference(sceneAssetBundleName);
                                contentDownloadItem.SceneAssetBundle.Retain();
                            }
                        }
                        else if (contentDownloadItem.State == ContentDownloadState.Unknown)
                        {
                            //Resource is not on disk any more, we release it
                            contentDownloadItem.ReleaseAssetBundles();
                        }
                    }

                    refreshYieldInstruction.Dispose();
                    contentDownloadItem.RefreshYieldInstruction = null;

                    contentDownloadItem.NotifyRefreshStateChange();
                }
            }
        }
Exemple #2
0
        private IEnumerator DownloadContent(ContentDownloadItem contentDownloadItem)
        {
            if (this.OnDownloaderDownloadStart != null)
            {
                this.OnDownloaderDownloadStart(contentDownloadItem);
            }

            string resourceAssetBundleName = contentDownloadItem.ContentInfo.ResourceAssetBundleName;
            string sceneAssetBundleName    = contentDownloadItem.ContentInfo.SceneAssetBundleName;


            if (contentDownloadItem.DownloadYieldInstruction != null)
            {
                contentDownloadItem.DownloadYieldInstruction.Dispose();
                contentDownloadItem.DownloadYieldInstruction = null;
            }

            using (AbstractDownloaderYieldInstruction downloadYieldInstruction = CreateDownloadYieldInstruction(resourceAssetBundleName, sceneAssetBundleName)) {
                contentDownloadItem.DownloadYieldInstruction = downloadYieldInstruction;

                contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Downloading);
                yield return(downloadYieldInstruction);

                if (!downloadYieldInstruction.IsDisposed)
                {
                    ContentDownloadError error = downloadYieldInstruction.DownloadError;
                    string errorMessage        = downloadYieldInstruction.DownloadErrorMessage;
                    if (error == ContentDownloadError.None &&
                        downloadYieldInstruction.ResourceAssetBundle != null &&
                        downloadYieldInstruction.SceneAssetBundle != null)
                    {
                        //Download Complete, we retain the resources directly on this contentDownloadItem

                        contentDownloadItem.ReleaseAssetBundles();
                        contentDownloadItem.ResourceAssetBundle = downloadYieldInstruction.ResourceAssetBundle;
                        contentDownloadItem.ResourceAssetBundle.Retain();
                        contentDownloadItem.SceneAssetBundle = downloadYieldInstruction.SceneAssetBundle;
                        contentDownloadItem.SceneAssetBundle.Retain();
                    }

                    downloadYieldInstruction.Dispose();
                    contentDownloadItem.DownloadYieldInstruction = null;

                    if (error != ContentDownloadError.None)
                    {
                        m_DownloadError = error;
                        contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Error, error);
                        if (this.OnDownloaderDownloadError != null)
                        {
                            this.OnDownloaderDownloadError(m_DownloadError, errorMessage, contentDownloadItem);
                        }

                        if (this.OnDownloaderDownloadFinish != null)
                        {
                            this.OnDownloaderDownloadFinish(contentDownloadItem, false);
                        }
                    }
                    else
                    {
                        contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Complete);

                        if (this.OnDownloaderDownloadFinish != null)
                        {
                            this.OnDownloaderDownloadFinish(contentDownloadItem, true);
                        }
                    }
                }
                else
                {
                    if (this.OnDownloaderDownloadFinish != null)
                    {
                        this.OnDownloaderDownloadFinish(contentDownloadItem, false);
                    }
                }
            }
        }