Exemple #1
0
 internal void RequestRefresh(ContentDownloadItem contentDownloadItem)
 {
     if (contentDownloadItem.State == ContentDownloadState.Complete || contentDownloadItem.State == ContentDownloadState.Unknown)
     {
         StartCoroutine(RefreshContent(contentDownloadItem));
     }
     else
     {
         contentDownloadItem.NotifyRefreshStateChange();
     }
 }
Exemple #2
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();
                }
            }
        }