Beispiel #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();
                }
            }
        }
Beispiel #2
0
        internal void ReleaseAssetBundles()
        {
            if (this.ResourceAssetBundle != null)
            {
                this.ResourceAssetBundle.Release();
                this.ResourceAssetBundle = null;
            }

            if (this.SceneAssetBundle != null)
            {
                this.SceneAssetBundle.Release();
                this.SceneAssetBundle = null;
            }
        }
Beispiel #3
0
        private IEnumerator Download(string resourceAssetBundleName, string sceneAssetBundleName)
        {
            if (AssetBundleOptions.UseAssetBundlesInEditor)
            {
                this.ProgressReport.Reset();

                Debug.LogFormat(DebugContext.SagoApp, "ContentDownloader-> Finding or creating reference to asset bundle: {0}", resourceAssetBundleName);
                this.ResourceAssetBundle = DownloadAssetBundleReference.FindOrCreateReference(resourceAssetBundleName);
                this.ResourceAssetBundle.Retain();

                this.ProgressReport.Index = 0;
                this.ProgressReport.Count = 2;
                this.ProgressReport.Item  = new LoadAssetBundleProgressReportItem(this.ResourceAssetBundle);
                yield return(this.ResourceAssetBundle);

                Debug.LogFormat(DebugContext.SagoApp, "ContentDownloader-> Completed finding or creating reference to asset bundle: {0}", resourceAssetBundleName);
                if (!string.IsNullOrEmpty(this.ResourceAssetBundle.error))
                {
                    Debug.LogError(this.ResourceAssetBundle.error, DebugContext.SagoApp);

                    m_DownloadError        = GetContentDownloadErrorFromString(this.ResourceAssetBundle.error);
                    m_DownloadErrorMessage = this.ResourceAssetBundle.error;

                    Complete();
                    yield break;
                }

                Debug.LogFormat(DebugContext.SagoApp, "ContentDownloader-> Finding or creating reference to asset bundle: {0}", sceneAssetBundleName);
                this.SceneAssetBundle = DownloadAssetBundleReference.FindOrCreateReference(sceneAssetBundleName);
                this.SceneAssetBundle.Retain();

                this.ProgressReport.Index = 1;
                this.ProgressReport.Item  = new LoadAssetBundleProgressReportItem(this.SceneAssetBundle);
                yield return(this.SceneAssetBundle);

                Debug.LogFormat(DebugContext.SagoApp, "ContentDownloader-> Completed finding or creating reference to asset bundle: {0}", sceneAssetBundleName);
                if (!string.IsNullOrEmpty(this.SceneAssetBundle.error))
                {
                    Debug.LogError(this.SceneAssetBundle.error, DebugContext.SagoApp);

                    m_DownloadError        = GetContentDownloadErrorFromString(this.SceneAssetBundle.error);
                    m_DownloadErrorMessage = this.SceneAssetBundle.error;

                    Complete();
                    yield break;
                }
            }

            Complete();
        }
Beispiel #4
0
        /// <summary>
        /// Finds an existing asset bundle reference for the specified asset bundle.
        /// </summary>
        /// <param name="assetBundleName">
        /// The name of the asset bundle.
        /// </param>
        public static DownloadAssetBundleReference FindReference(string assetBundleName)
        {
            if (string.IsNullOrEmpty(assetBundleName))
            {
                throw new System.ArgumentNullException("assetBundleName");
            }

            if (References.ContainsKey(assetBundleName))
            {
                DownloadAssetBundleReference reference = References[assetBundleName];
                reference.Retain();
                reference.Autorelease();
                return(reference);
            }

            return(null);
        }
 public LoadAssetBundleProgressReportItem(DownloadAssetBundleReference assetBundleReference)
 {
     AssetBundleReference = assetBundleReference;
 }