/// <summary>
        /// オンラインプロセス開始イベント
        /// </summary>
        /// <returns>コルーチン</returns>
        protected override System.Collections.IEnumerator OnStartedOnlineProcess()
        {
            m_ErrorCode = AssetBundleErrorCode.Null;

            var fileNameAndURL = manager.GetAssetBundleFileNameAndURL(nameWithVariant);

            m_DownloadWork = new DownloadWork {
                url      = fileNameAndURL.url,
                fullPath = manager.GetDeliveryStreamingAssetsCacheFullPath(fileNameAndURL.fileName),
                hash     = manager.catalog.GetAssetBundleHash(nameWithVariant),
                crc      = manager.catalog.GetAssetBundleCrc(nameWithVariant),
                fileSize = manager.catalog.GetAssetBundleFileSize(nameWithVariant)
            };

            var hasCache = manager.HasCacheForDeliveryStreamingAsset(nameWithVariant);

            if (!hasCache)
            {
                //キャッシュ無効
                m_DownloadWork.request = new UnityWebRequest(m_DownloadWork.url
                                                             , UnityWebRequest.kHttpVerbGET
                                                             , new DownloadHandlerDeliveryStreamingAsset(m_DownloadWork.fullPath, m_DownloadWork.hash, 0, (int)m_DownloadWork.fileSize)
                                                             , null
                                                             );
                var sendWebRequest = m_DownloadWork.request.SendWebRequest();
                var progress       = -1.0f;
                var startTime      = Time.realtimeSinceStartup;
                while (!sendWebRequest.isDone)
                {
                    yield return(null);

                    if (progress != sendWebRequest.progress)
                    {
                        //進行
                        progress  = sendWebRequest.progress;
                        startTime = Time.realtimeSinceStartup;
                    }
                    else if (manager.downloadTimeoutSeconds < (Time.realtimeSinceStartup - startTime))
                    {
                        //タイムアウト時間の停滞
                        break;
                    }
                }

                if (!m_DownloadWork.request.isDone || m_DownloadWork.request.isNetworkError || m_DownloadWork.request.isHttpError)
                {
                    AssetBundleErrorCodeUtility.TryParse(m_DownloadWork.request, out m_ErrorCode);
                }
            }

            yield return(base.OnStartedOnlineProcess());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// オンラインプロセス開始イベント
        /// </summary>
        /// <returns>コルーチン</returns>
        protected override System.Collections.IEnumerator OnStartedOnlineProcess()
        {
            m_ErrorCode = AssetBundleErrorCode.Null;

            var fileNameAndURL = manager.GetAssetBundleFileNameAndURL(nameWithVariant);

            m_DownloadWork = new DownloadWork {
                url  = fileNameAndURL.url,
                hash = manager.catalog.GetAssetBundleHash(nameWithVariant),
                crc  = manager.catalog.GetAssetBundleCrc(nameWithVariant)
            };
#if UNITY_2018_1_OR_NEWER
            m_DownloadWork.request = UnityWebRequestAssetBundle.GetAssetBundle(m_DownloadWork.url, m_DownloadWork.hash, m_DownloadWork.crc);
#else
            m_DownloadWork.request = UnityWebRequest.GetAssetBundle(m_DownloadWork.url, m_DownloadWork.hash, m_DownloadWork.crc);
#endif
            var sendWebRequest = m_DownloadWork.request.SendWebRequest();
            var progress       = -1.0f;
            var startTime      = Time.realtimeSinceStartup;
            while (!sendWebRequest.isDone)
            {
                yield return(null);

                if (progress != sendWebRequest.progress)
                {
                    //進行
                    progress  = sendWebRequest.progress;
                    startTime = Time.realtimeSinceStartup;
                }
                else if (manager.downloadTimeoutSeconds < (Time.realtimeSinceStartup - startTime))
                {
                    //タイムアウト時間の停滞
                    break;
                }
            }

            if (m_DownloadWork.request.isNetworkError || m_DownloadWork.request.isHttpError)
            {
                AssetBundleErrorCodeUtility.TryParse(m_DownloadWork.request, out m_ErrorCode);
            }
            else
            {
                Caching.ClearOtherCachedVersions(fileNameAndURL.fileName, m_DownloadWork.hash);
            }

            yield return(base.OnStartedOnlineProcess());
        }