Example #1
0
 private void NotifyAll(ContentDownloadState state, ContentDownloadError error = ContentDownloadError.None)
 {
     foreach (ContentDownloadItem contentDownloadItem in DownloadQueue.ToArray())
     {
         contentDownloadItem.NotifyDownloadStateChange(state, error);
     }
 }
Example #2
0
 public AbstractDownloaderYieldInstruction(MonoBehaviour monoBehaviour)
 {
     m_MonoBehaviour     = null;
     m_Coroutine         = null;
     m_IsDone            = false;
     m_IsDisposed        = false;
     m_DownloadState     = ContentDownloadState.Unknown;
     m_DownloadError     = ContentDownloadError.None;
     this.ProgressReport = new ProgressReport();
 }
Example #3
0
        public void Dispose()
        {
            if (m_MonoBehaviour != null && m_Coroutine != null)
            {
                m_DownloadState = ContentDownloadState.Unknown;
                m_DownloadError = ContentDownloadError.None;
                m_MonoBehaviour.StopCoroutine(m_Coroutine);
                Complete();
            }

            ReleaseAssetBundles();

            m_IsDisposed = true;
        }
Example #4
0
 public MockDownloadYieldInstruction(MonoBehaviour monoBehaviour, float mockDownloadTime,
                                     ContentDownloadError mockError) : base(monoBehaviour)
 {
     if (monoBehaviour != null)
     {
         m_MockDownloadTime = mockDownloadTime;
         m_MockError        = mockError;
         m_MonoBehaviour    = monoBehaviour;
         m_Coroutine        = Download();
         m_MonoBehaviour.StartCoroutine(m_Coroutine);
     }
     else
     {
         m_IsDone = true;
         Debug.LogError("ContentDownloader-MockDownloadYieldInstruction-> MonoBehaviour reference passed is null.", DebugContext.SagoApp);
     }
 }
Example #5
0
        /// <summary>
        /// Constantly check for internet connection after given delay.
        /// If we are not already in LostInternet/LostWiFi error state, notifies everyone of NoWiFi/NoInternet state.
        /// </summary>
        /// <param name="delay">Interval before each internet connection test.</param>
        private IEnumerator WaitForInternetConnection(float delay)
        {
            while (!this.DownloadQueue.IsEmpty())
            {
                using (InternetReachabilityYieldInstruction reachabilityYieldInstruction = new InternetReachabilityYieldInstruction(this)) {
                    yield return(reachabilityYieldInstruction);

                    if (this.DownloadQueue.IsEmpty())
                    {
                        break;
                    }

                    if (!reachabilityYieldInstruction.IsInternetReachable)
                    {
                        if (m_DownloadError == ContentDownloadError.None)
                        {
                            if (DownloadViaWiFiOnly)
                            {
                                m_DownloadError = ContentDownloadError.NoWifi;
                                NotifyAll(ContentDownloadState.Error, ContentDownloadError.NoWifi);
                                NotifyAll(ContentDownloadState.Queued);
                            }
                            else
                            {
                                m_DownloadError = ContentDownloadError.NoInternet;
                                NotifyAll(ContentDownloadState.Error, ContentDownloadError.NoInternet);
                                NotifyAll(ContentDownloadState.Queued);
                            }

                            if (this.OnDownloaderDownloadError != null)
                            {
                                this.OnDownloaderDownloadError(m_DownloadError, NoInternetErrorMessage, this.DownloadQueue.GetFirst());
                            }
                        }
                    }
                    else
                    {
                        yield break;
                    }
                }

                yield return(new WaitForSeconds(delay));
            }
        }
Example #6
0
        private IEnumerator DownloadAll()
        {
            while (true)
            {
                if (!this.DownloadQueue.IsEmpty())
                {
                    //Check for internet connection before starting/restarting download
                    //Used to return NoInternet/NoWifi error states
                    m_DownloadError = ContentDownloadError.None;
                    yield return(StartCoroutine(WaitForInternetConnection(InternetConnectionCheckDelay)));

                    //Dequeue next download and starts it
                    ContentDownloadItem contentDownloadItem;
                    while ((contentDownloadItem = this.DownloadQueue.RemoveFirst()) != null)
                    {
                        m_DownloadError = ContentDownloadError.None;
                        yield return(StartCoroutine(DownloadContent(contentDownloadItem)));

                        if (m_DownloadError != ContentDownloadError.None)
                        {
                            if (m_DownloadError == ContentDownloadError.LostInternet || m_DownloadError == ContentDownloadError.LostWifi)
                            {
                                //LostInternet/LostWifi : Queue back this one and wait
                                this.DownloadQueue.AddFirst(contentDownloadItem);
                                contentDownloadItem.NotifyDownloadStateChange(ContentDownloadState.Queued);

                                yield return(StartCoroutine(WaitForInternetConnection(InternetConnectionCheckDelay)));
                            }
                            else if (m_DownloadError == ContentDownloadError.RunOutOfDiskSpace)
                            {
                                //LowDiskSpace : NotifyError
                                NotifyAndDequeueAll(ContentDownloadState.Error, contentDownloadItem.Error);
                            }
                        }
                    }
                }

                yield return(null);
            }
        }
Example #7
0
        public static string ToAnalyticsError(this ContentDownloadError error)
        {
            switch (error)
            {
            case ContentDownloadError.NoWifi:
            case ContentDownloadError.LostWifi:
                return("OdrErrorNoWiFi");

            case ContentDownloadError.NoInternet:
            case ContentDownloadError.LostInternet:
                return("OdrErrorNoInternet");

            case ContentDownloadError.InsufficientDiskSpace:
            case ContentDownloadError.RunOutOfDiskSpace:
                return("LowDiskSpace");

            case ContentDownloadError.None:
                return("None");

            default:
                return("OdrErrorUnknown");
            }
        }
Example #8
0
        internal void NotifyDownloadStateChange(ContentDownloadState state, ContentDownloadError error = ContentDownloadError.None)
        {
            if (this.State != state || this.Error != error)
            {
                string submoduleName = "Unknown";
                if (this.ContentInfo != null)
                {
                    submoduleName = this.ContentInfo.SubmoduleName;
                }

                Debug.LogFormat("ContentDownloader->State changed for {0} : State = {1}, Error = {2}",
                                submoduleName,
                                state.ToString(),
                                error.ToString());

                this.State = state;
                this.Error = error;

                if (this.OnDownloadStateChange != null)
                {
                    this.OnDownloadStateChange(this);
                }
            }
        }
Example #9
0
 private void NotifyAndDequeueAll(ContentDownloadState state, ContentDownloadError error = ContentDownloadError.None)
 {
     NotifyAll(state, error);
     DownloadQueue.Clear();
 }
Example #10
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);
                    }
                }
            }
        }