internal override void Update()
        {
            if (_steps == ESteps.None || _steps == ESteps.Done)
            {
                return;
            }

            if (_steps == ESteps.Update)
            {
                _appManifestLoader.Update();
                Progress = _appManifestLoader.Progress();
                if (_appManifestLoader.IsDone() == false)
                {
                    return;
                }

                if (_appManifestLoader.Result == null)
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = _appManifestLoader.Error;
                }
                else
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Succeed;
                    _impl.SetAppPatchManifest(_appManifestLoader.Result);
                }
            }
        }
		internal override void Update()
		{
			if (_steps == ESteps.None || _steps == ESteps.Done)
				return;

			if (_steps == ESteps.UnLoad)
			{
				if (_scene.IsValid() && _scene.isLoaded)
				{
					_asyncOp = SceneManager.UnloadSceneAsync(_scene);
					_steps = ESteps.Checking;
				}
				else
				{
					Error = "Scene is invalid or is not loaded.";
					_steps = ESteps.Done;
					Status = EOperationStatus.Failed;
				}
			}

			if (_steps == ESteps.Checking)
			{
				Progress = _asyncOp.progress;
				if (_asyncOp.isDone == false)
					return;

				_steps = ESteps.Done;
				Status = EOperationStatus.Succeed;
			}
		}
        internal override void Update()
        {
            if (_steps == ESteps.Builder)
            {
                _simulatePatchManifestPath = EditorSimulateModeHelper.SimulateBuild();
                if (string.IsNullOrEmpty(_simulatePatchManifestPath))
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = "Simulate build failed, see the detail info on the console window.";
                    return;
                }
                _steps = ESteps.Load;
            }

            if (_steps == ESteps.Load)
            {
                if (File.Exists(_simulatePatchManifestPath) == false)
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = $"Manifest file not found : {_simulatePatchManifestPath}";
                    return;
                }

                YooLogger.Log($"Load manifest file : {_simulatePatchManifestPath}");
                string jsonContent           = FileUtility.ReadFile(_simulatePatchManifestPath);
                var    simulatePatchManifest = PatchManifest.Deserialize(jsonContent);
                _impl.SetSimulatePatchManifest(simulatePatchManifest);
                _steps = ESteps.Done;
                Status = EOperationStatus.Succeed;
            }
        }
Exemplo n.º 4
0
 public void SendRequest(int failedTryAgain, int timeout)
 {
     if (_steps == ESteps.None)
     {
         _failedTryAgain = failedTryAgain;
         _timeout        = timeout;
         _steps          = ESteps.CreateDownload;
     }
 }
 internal override void Start()
 {
     if (string.IsNullOrEmpty(_simulatePatchManifestPath))
     {
         _steps = ESteps.Builder;
     }
     else
     {
         _steps = ESteps.Load;
     }
 }
Exemplo n.º 6
0
        internal override void Update()
        {
            if (_steps == ESteps.None || _steps == ESteps.Done)
            {
                return;
            }

            // 1. 准备工作
            if (_steps == ESteps.Prepare)
            {
                if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromEditor)
                {
                    _steps = ESteps.CheckAndCopyFile;
                    return;                     // 模拟实现异步操作
                }
                else
                {
                    throw new System.NotImplementedException(_bundleInfo.LoadMode.ToString());
                }
            }

            // 2. 检测并拷贝原生文件
            if (_steps == ESteps.CheckAndCopyFile)
            {
                // 如果不需要保存文件
                if (string.IsNullOrEmpty(CopyPath))
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Succeed;
                    return;
                }

                // 如果原生文件已经存在,则将其删除
                if (File.Exists(CopyPath))
                {
                    File.Delete(CopyPath);
                }

                try
                {
                    FileUtility.CreateFileDirectory(CopyPath);
                    File.Copy(GetCachePath(), CopyPath, true);
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Succeed;
                }
                catch (System.Exception e)
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = e.ToString();
                }
            }
        }
        internal override void Update()
        {
            if (_steps == ESteps.None || _steps == ESteps.Done)
            {
                return;
            }

            if (_steps == ESteps.InitCache)
            {
                // 每次启动时比对APP版本号是否一致
                CacheData cacheData = CacheData.LoadCache();
                if (cacheData.CacheAppVersion != Application.version)
                {
                    YooLogger.Warning($"Cache is dirty ! Cache application version is {cacheData.CacheAppVersion}, Current application version is {Application.version}");

                    // 注意:在覆盖安装的时候,会保留APP沙盒目录,可以选择清空缓存目录
                    if (_impl.ClearCacheWhenDirty)
                    {
                        YooLogger.Warning("Clear cache files.");
                        SandboxHelper.DeleteCacheFolder();
                    }

                    // 更新缓存文件
                    CacheData.UpdateCache();
                }
                _steps = ESteps.Update;
            }

            if (_steps == ESteps.Update)
            {
                _appManifestLoader.Update();
                Progress = _appManifestLoader.Progress();
                if (_appManifestLoader.IsDone() == false)
                {
                    return;
                }

                if (_appManifestLoader.Result == null)
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = _appManifestLoader.Error;
                }
                else
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Succeed;
                    _impl.SetAppPatchManifest(_appManifestLoader.Result);
                    _impl.SetLocalPatchManifest(_appManifestLoader.Result);
                }
            }
        }
        internal override void Update()
        {
            if (_steps == ESteps.None || _steps == ESteps.Done)
            {
                return;
            }

            if (_steps == ESteps.Clone)
            {
                if (_handle.IsValid == false)
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = $"{nameof(AssetOperationHandle)} is invalid.";
                    return;
                }

                if (_handle.AssetObject == null)
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = $"{nameof(AssetOperationHandle.AssetObject)} is null.";
                    return;
                }

                if (_setPositionRotation)
                {
                    if (_parent == null)
                    {
                        Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation);
                    }
                    else
                    {
                        Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation, _parent);
                    }
                }
                else
                {
                    if (_parent == null)
                    {
                        Result = Object.Instantiate(_handle.AssetObject as GameObject);
                    }
                    else
                    {
                        Result = Object.Instantiate(_handle.AssetObject as GameObject, _parent);
                    }
                }

                _steps = ESteps.Done;
                Status = EOperationStatus.Succeed;
            }
        }
Exemplo n.º 9
0
        internal override void Update()
        {
            if (_steps == ESteps.None || _steps == ESteps.Done)
            {
                return;
            }

            if (_steps == ESteps.LoadWebManifest)
            {
                string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion));
                YooLogger.Log($"Beginning to request patch manifest : {webURL}");
                _downloader = new UnityWebDataRequester();
                _downloader.SendRequest(webURL, _timeout);
                _steps = ESteps.CheckWebManifest;
            }

            if (_steps == ESteps.CheckWebManifest)
            {
                Progress = _downloader.Progress();
                if (_downloader.IsDone() == false)
                {
                    return;
                }

                // Check error
                if (_downloader.HasError())
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = _downloader.GetError();
                }
                else
                {
                    // 解析补丁清单
                    if (ParseRemotePatchManifest(_downloader.GetText()))
                    {
                        _steps = ESteps.Done;
                        Status = EOperationStatus.Succeed;
                    }
                    else
                    {
                        _steps = ESteps.Done;
                        Status = EOperationStatus.Failed;
                        Error  = $"URL : {_downloader.URL} Error : remote patch manifest content is invalid";
                    }
                }
                _downloader.Dispose();
            }
        }
Exemplo n.º 10
0
        internal override void Update()
        {
            if (_steps == ESteps.None || _steps == ESteps.Done)
            {
                return;
            }

            if (_steps == ESteps.LoadStaticVersion)
            {
                string webURL = GetStaticVersionRequestURL(YooAssetSettings.VersionFileName);
                YooLogger.Log($"Beginning to request static version : {webURL}");
                _downloader = new UnityWebDataRequester();
                _downloader.SendRequest(webURL, _timeout);
                _steps = ESteps.CheckStaticVersion;
            }

            if (_steps == ESteps.CheckStaticVersion)
            {
                Progress = _downloader.Progress();
                if (_downloader.IsDone() == false)
                {
                    return;
                }

                if (_downloader.HasError())
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = _downloader.GetError();
                }
                else
                {
                    if (int.TryParse(_downloader.GetText(), out int value))
                    {
                        ResourceVersion = value;
                        _steps          = ESteps.Done;
                        Status          = EOperationStatus.Succeed;
                    }
                    else
                    {
                        _steps = ESteps.Done;
                        Status = EOperationStatus.Failed;
                        Error  = $"URL : {_downloader.URL} Error : static version content is invalid.";
                    }
                }
                _downloader.Dispose();
            }
        }
Exemplo n.º 11
0
		internal override void Start()
		{
			if (_flag == EFlag.Normal)
			{
				_steps = ESteps.UnLoad;
			}
			else if (_flag == EFlag.Error)
			{
				_steps = ESteps.Done;
				Status = EOperationStatus.Failed;
			}
			else
			{
				throw new System.NotImplementedException(_flag.ToString());
			}
		}
        public ApresentanteValidador(ESteps stepCorrente)
        {
            switch (stepCorrente)
            {
            case ESteps.Contato:
                RuleFor(t => t.Contato).NotEmpty();
                RuleFor(t => t.Financeiro).NotEmpty();
                RuleFor(t => t.DadosBasicos).NotEmpty();
                break;

            case ESteps.Financeiro:
                RuleFor(t => t.Financeiro).NotEmpty();
                RuleFor(t => t.DadosBasicos).NotEmpty();
                break;

            default:
                RuleFor(t => t.DadosBasicos).NotEmpty();
                break;
            }
            ;
        }
Exemplo n.º 13
0
        internal override void Update()
        {
            if (_steps == ESteps.None || _steps == ESteps.Done)
            {
                return;
            }

            if (_steps == ESteps.Check)
            {
                if (_downloadList == null)
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = "Download list is null.";
                }
                else
                {
                    _steps = ESteps.Loading;
                }
            }

            if (_steps == ESteps.Loading)
            {
                // 检测下载器结果
                _removeList.Clear();
                long downloadBytes = CurrentDownloadBytes;
                foreach (var downloader in _downloaders)
                {
                    downloadBytes += (long)downloader.DownloadedBytes;
                    if (downloader.IsDone() == false)
                    {
                        continue;
                    }

                    BundleInfo bundleInfo = downloader.GetBundleInfo();

                    // 检测是否下载失败
                    if (downloader.HasError())
                    {
                        _removeList.Add(downloader);
                        _loadFailedList.Add(bundleInfo);
                        continue;
                    }

                    // 下载成功
                    _removeList.Add(downloader);
                    CurrentDownloadCount++;
                    CurrentDownloadBytes += bundleInfo.SizeBytes;
                }

                // 移除已经完成的下载器(无论成功或失败)
                foreach (var loader in _removeList)
                {
                    _downloaders.Remove(loader);
                }

                // 如果下载进度发生变化
                if (_lastDownloadBytes != downloadBytes || _lastDownloadCount != CurrentDownloadCount)
                {
                    _lastDownloadBytes = downloadBytes;
                    _lastDownloadCount = CurrentDownloadCount;
                    Progress           = (float)_lastDownloadBytes / TotalDownloadBytes;
                    OnDownloadProgressCallback?.Invoke(TotalDownloadCount, _lastDownloadCount, TotalDownloadBytes, _lastDownloadBytes);
                }

                // 动态创建新的下载器到最大数量限制
                // 注意:如果期间有下载失败的文件,暂停动态创建下载器
                if (_downloadList.Count > 0 && _loadFailedList.Count == 0)
                {
                    if (_isPause)
                    {
                        return;
                    }

                    if (_downloaders.Count < _downloadingMaxNumber)
                    {
                        int index     = _downloadList.Count - 1;
                        var operation = DownloadSystem.BeginDownload(_downloadList[index], _failedTryAgain);
                        _downloaders.Add(operation);
                        _downloadList.RemoveAt(index);
                    }
                }

                // 下载结算
                if (_downloaders.Count == 0)
                {
                    if (_loadFailedList.Count > 0)
                    {
                        string fileName = _loadFailedList[0].BundleName;
                        Error  = $"Failed to download file : {fileName}";
                        _steps = ESteps.Done;
                        Status = EOperationStatus.Failed;
                        OnDownloadFileFailedCallback?.Invoke(fileName);
                        OnDownloadOverCallback?.Invoke(false);
                    }
                    else
                    {
                        // 结算成功
                        _steps = ESteps.Done;
                        Status = EOperationStatus.Succeed;
                        OnDownloadOverCallback?.Invoke(true);
                    }
                }
            }
        }
Exemplo n.º 14
0
 internal override void Start()
 {
     RequestCount++;
     _steps = ESteps.LoadStaticVersion;
 }
 internal override void Start()
 {
     _steps = ESteps.Update;
 }
 internal override void Start()
 {
     _steps = ESteps.InitCache;
 }
Exemplo n.º 17
0
 internal override void Start()
 {
     _steps = ESteps.Clone;
 }
Exemplo n.º 18
0
 public Workflow(ESteps stepCorrente)
 => StepCorrente = stepCorrente;
Exemplo n.º 19
0
        internal override void Update()
        {
            if (_steps == ESteps.None || _steps == ESteps.Done)
            {
                return;
            }

            if (_steps == ESteps.LoadWebManifestHash)
            {
                string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestHashFileName(_resourceVersion));
                YooLogger.Log($"Beginning to request patch manifest hash : {webURL}");
                _downloader1 = new UnityWebDataRequester();
                _downloader1.SendRequest(webURL, _timeout);
                _steps = ESteps.CheckWebManifestHash;
            }

            if (_steps == ESteps.CheckWebManifestHash)
            {
                if (_downloader1.IsDone() == false)
                {
                    return;
                }

                // Check error
                if (_downloader1.HasError())
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = _downloader1.GetError();
                }
                else
                {
                    string webManifestHash    = _downloader1.GetText();
                    string cachedManifestHash = GetSandboxPatchManifestFileHash(_resourceVersion);

                    // 如果补丁清单文件的哈希值相同
                    if (cachedManifestHash == webManifestHash)
                    {
                        YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}");
                        LoadSandboxPatchManifest(_resourceVersion);
                        _steps = ESteps.InitVerifyingCache;
                    }
                    else
                    {
                        YooLogger.Log($"Patch manifest hash is change : {webManifestHash} -> {cachedManifestHash}");
                        _steps = ESteps.LoadWebManifest;
                    }
                }
                _downloader1.Dispose();
            }

            if (_steps == ESteps.LoadWebManifest)
            {
                string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion));
                YooLogger.Log($"Beginning to request patch manifest : {webURL}");
                _downloader2 = new UnityWebDataRequester();
                _downloader2.SendRequest(webURL, _timeout);
                _steps = ESteps.CheckWebManifest;
            }

            if (_steps == ESteps.CheckWebManifest)
            {
                if (_downloader2.IsDone() == false)
                {
                    return;
                }

                // Check error
                if (_downloader2.HasError())
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = _downloader2.GetError();
                }
                else
                {
                    // 解析补丁清单
                    if (ParseAndSaveRemotePatchManifest(_resourceVersion, _downloader2.GetText()))
                    {
                        _steps = ESteps.InitVerifyingCache;
                    }
                    else
                    {
                        _steps = ESteps.Done;
                        Status = EOperationStatus.Failed;
                        Error  = $"URL : {_downloader2.URL} Error : remote patch manifest content is invalid";
                    }
                }
                _downloader2.Dispose();
            }

            if (_steps == ESteps.InitVerifyingCache)
            {
                InitVerifyingCache();
                _verifyTime = UnityEngine.Time.realtimeSinceStartup;
                _steps      = ESteps.UpdateVerifyingCache;
            }

            if (_steps == ESteps.UpdateVerifyingCache)
            {
                Progress = GetVerifyProgress();
                if (UpdateVerifyingCache())
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Succeed;
                    float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
                    YooLogger.Log($"Verify result : Success {_verifySuccessCount}, Fail {_verifyFailCount}, Elapsed time {costTime} seconds");
                }
            }
        }
Exemplo n.º 20
0
        internal override void Update()
        {
            if (_steps == ESteps.None || _steps == ESteps.Done)
            {
                return;
            }

            // 1. 准备工作
            if (_steps == ESteps.Prepare)
            {
                if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.None)
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = $"Bundle info is invalid : {_bundleInfo.BundleName}";
                }
                else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
                {
                    _steps = ESteps.DownloadFromWeb;
                }
                else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
                {
                    _steps = ESteps.DownloadFromApk;
                }
                else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
                {
                    _steps = ESteps.CheckAndCopyFile;
                }
                else
                {
                    throw new System.NotImplementedException(_bundleInfo.LoadMode.ToString());
                }
            }

            // 2. 从服务器下载
            if (_steps == ESteps.DownloadFromWeb)
            {
                int failedTryAgain = int.MaxValue;
                _downloader = DownloadSystem.BeginDownload(_bundleInfo, failedTryAgain);
                _steps      = ESteps.CheckDownloadFromWeb;
            }

            // 3. 检测服务器下载结果
            if (_steps == ESteps.CheckDownloadFromWeb)
            {
                Progress = _downloader.DownloadProgress;
                if (_downloader.IsDone() == false)
                {
                    return;
                }

                if (_downloader.HasError())
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = _downloader.GetLastError();
                }
                else
                {
                    _steps = ESteps.CheckAndCopyFile;
                }
            }

            // 4. 从APK拷贝文件
            if (_steps == ESteps.DownloadFromApk)
            {
                string downloadURL = PathHelper.ConvertToWWWPath(_bundleInfo.GetStreamingLoadPath());
                _fileRequester = new UnityWebFileRequester();
                _fileRequester.SendRequest(downloadURL, GetCachePath());
                _steps = ESteps.CheckDownloadFromApk;
            }

            // 5. 检测APK拷贝文件结果
            if (_steps == ESteps.CheckDownloadFromApk)
            {
                Progress = _fileRequester.Progress();
                if (_fileRequester.IsDone() == false)
                {
                    return;
                }

                if (_fileRequester.HasError())
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = _fileRequester.GetError();
                }
                else
                {
                    _steps = ESteps.CheckAndCopyFile;
                }
                _fileRequester.Dispose();
            }

            // 6. 检测并拷贝原生文件
            if (_steps == ESteps.CheckAndCopyFile)
            {
                // 如果不需要保存文件
                if (string.IsNullOrEmpty(CopyPath))
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Succeed;
                    return;
                }

                // 如果原生文件已经存在,则验证其完整性
                if (File.Exists(CopyPath))
                {
                    bool result = DownloadSystem.CheckContentIntegrity(CopyPath, _bundleInfo.SizeBytes, _bundleInfo.CRC);
                    if (result)
                    {
                        _steps = ESteps.Done;
                        Status = EOperationStatus.Succeed;
                        return;
                    }
                    else
                    {
                        File.Delete(CopyPath);
                    }
                }

                try
                {
                    FileUtility.CreateFileDirectory(CopyPath);
                    File.Copy(GetCachePath(), CopyPath, true);
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Succeed;
                }
                catch (System.Exception e)
                {
                    _steps = ESteps.Done;
                    Status = EOperationStatus.Failed;
                    Error  = e.ToString();
                }
            }
        }
        public void Update()
        {
            if (IsDone())
            {
                return;
            }

            if (_steps == ESteps.LoadStaticVersion)
            {
                YooLogger.Log($"Load application static version.");
                string filePath = PathHelper.MakeStreamingLoadPath(YooAssetSettings.VersionFileName);
                string url      = PathHelper.ConvertToWWWPath(filePath);
                _downloader1 = new UnityWebDataRequester();
                _downloader1.SendRequest(url);
                _steps = ESteps.CheckStaticVersion;
            }

            if (_steps == ESteps.CheckStaticVersion)
            {
                if (_downloader1.IsDone() == false)
                {
                    return;
                }

                if (_downloader1.HasError())
                {
                    Error  = _downloader1.GetError();
                    _steps = ESteps.Failed;
                }
                else
                {
                    _staticVersion = int.Parse(_downloader1.GetText());
                    _steps         = ESteps.LoadAppManifest;
                }
                _downloader1.Dispose();
            }

            if (_steps == ESteps.LoadAppManifest)
            {
                YooLogger.Log($"Load application patch manifest.");
                string filePath = PathHelper.MakeStreamingLoadPath(YooAssetSettingsData.GetPatchManifestFileName(_staticVersion));
                string url      = PathHelper.ConvertToWWWPath(filePath);
                _downloader2 = new UnityWebDataRequester();
                _downloader2.SendRequest(url);
                _steps = ESteps.CheckAppManifest;
            }

            if (_steps == ESteps.CheckAppManifest)
            {
                if (_downloader2.IsDone() == false)
                {
                    return;
                }

                if (_downloader2.HasError())
                {
                    Error  = _downloader2.GetError();
                    _steps = ESteps.Failed;
                }
                else
                {
                    // 解析APP里的补丁清单
                    Result = PatchManifest.Deserialize(_downloader2.GetText());
                    _steps = ESteps.Succeed;
                }
                _downloader2.Dispose();
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// 轮询更新
        /// </summary>
        public override void Update()
        {
            if (_steps == ESteps.Done)
            {
                return;
            }

            if (_steps == ESteps.None)
            {
                if (MainBundleInfo.IsInvalid)
                {
                    _steps    = ESteps.Done;
                    Status    = EStatus.Failed;
                    LastError = $"The bundle info is invalid : {MainBundleInfo.BundleName}";
                    YooLogger.Error(LastError);
                    return;
                }

                if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
                {
                    _steps  = ESteps.LoadFile;
                    _webURL = MainBundleInfo.GetStreamingLoadPath();
                }
                else
                {
                    throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
                }
            }

            // 1. 从服务器或缓存中获取AssetBundle文件
            if (_steps == ESteps.LoadFile)
            {
                string hash = StringUtility.RemoveExtension(MainBundleInfo.Hash);
                _webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_webURL, Hash128.Parse(hash));
                _webRequest.SendWebRequest();
                _steps = ESteps.CheckFile;
            }

            // 2. 检测获取的AssetBundle文件
            if (_steps == ESteps.CheckFile)
            {
                if (_webRequest.isDone == false)
                {
                    return;
                }

#if UNITY_2020_1_OR_NEWER
                if (_webRequest.result != UnityWebRequest.Result.Success)
#else
                if (_webRequest.isNetworkError || _webRequest.isHttpError)
#endif
                {
                    YooLogger.Warning($"Failed to get asset bundle form web : {_webURL} Error : {_webRequest.error}");
                    _steps    = ESteps.TryLoad;
                    _tryTimer = 0;
                }
                else
                {
                    CacheBundle = DownloadHandlerAssetBundle.GetContent(_webRequest);
                    if (CacheBundle == null)
                    {
                        _steps    = ESteps.Done;
                        Status    = EStatus.Failed;
                        LastError = $"AssetBundle file is invalid : {MainBundleInfo.BundleName}";
                        YooLogger.Error(LastError);
                    }
                    else
                    {
                        _steps = ESteps.Done;
                        Status = EStatus.Succeed;
                    }
                }
            }

            // 3. 如果获取失败,重新尝试
            if (_steps == ESteps.TryLoad)
            {
                _tryTimer += Time.unscaledDeltaTime;
                if (_tryTimer > 1f)
                {
                    _webRequest.Dispose();
                    _webRequest = null;
                    _steps      = ESteps.LoadFile;
                }
            }
        }
Exemplo n.º 23
0
 internal override void Start()
 {
     YooLogger.Log($"Begine to download : {TotalDownloadCount} files and {TotalDownloadBytes} bytes");
     _steps = ESteps.Check;
 }
Exemplo n.º 24
0
        private async Task <HttpResponseMessage> HttpSendPostAsync(string jsonMessage, ESteps step)
        {
            HttpClient         httpClient;
            HttpRequestMessage req;
            StringBuilder      uriStrBuilder = new StringBuilder(host);

            using (httpClient = new HttpClient())
            {
                using (req = new HttpRequestMessage())
                {
                    if (ESteps.Publish == step)
                    {
                        uriStrBuilder.Append(publishPath);
                    }
                    else
                    {
                        jsonMessage = string.Concat("[", jsonMessage, "]");
                        uriStrBuilder.Append(path);
                        if (ESteps.Add == step)
                        {
                            uriStrBuilder.Append("examples");
                        }
                        else
                        {
                            uriStrBuilder.Append("train");
                        }
                    }
                    req.Method     = HttpMethod.Post;
                    req.RequestUri = new Uri(uriStrBuilder.ToString());
                    req.Headers.Add("Ocp-Apim-Subscription-Key", authoringKey);
                    req.Content = new StringContent(jsonMessage, Encoding.UTF8, "text/json");

                    debug += string.Concat("URL = ", req.RequestUri.AbsoluteUri, "\r\nBody Contents = ", jsonMessage);

                    return(await httpClient.SendAsync(req));
                }
            }
        }
Exemplo n.º 25
0
 internal override void Start()
 {
     _steps = ESteps.Prepare;
 }
Exemplo n.º 26
0
 internal override void Start()
 {
     RequestCount++;
     _steps = ESteps.LoadWebManifest;
 }
Exemplo n.º 27
0
        /// <summary>
        /// 轮询更新
        /// </summary>
        public override void Update()
        {
            if (_steps == ESteps.Done)
            {
                return;
            }

            if (_steps == ESteps.None)
            {
                if (MainBundleInfo.IsInvalid)
                {
                    _steps    = ESteps.Done;
                    Status    = EStatus.Failed;
                    LastError = $"The bundle info is invalid : {MainBundleInfo.BundleName}";
                    YooLogger.Error(LastError);
                    return;
                }

                if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
                {
                    _steps        = ESteps.Download;
                    _fileLoadPath = MainBundleInfo.GetCacheLoadPath();
                }
                else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
                {
                    _steps        = ESteps.LoadFile;
                    _fileLoadPath = MainBundleInfo.GetStreamingLoadPath();
                }
                else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
                {
                    _steps        = ESteps.LoadFile;
                    _fileLoadPath = MainBundleInfo.GetCacheLoadPath();
                }
                else
                {
                    throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
                }
            }

            // 1. 从服务器下载
            if (_steps == ESteps.Download)
            {
                int failedTryAgain = int.MaxValue;
                _downloader = DownloadSystem.BeginDownload(MainBundleInfo, failedTryAgain);
                _steps      = ESteps.CheckDownload;
            }

            // 2. 检测服务器下载结果
            if (_steps == ESteps.CheckDownload)
            {
                if (_downloader.IsDone() == false)
                {
                    return;
                }

                if (_downloader.HasError())
                {
                    _steps    = ESteps.Done;
                    Status    = EStatus.Failed;
                    LastError = _downloader.GetLastError();
                }
                else
                {
                    _steps = ESteps.LoadFile;
                }
            }

            // 3. 加载AssetBundle
            if (_steps == ESteps.LoadFile)
            {
#if UNITY_EDITOR
                // 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
                if (System.IO.File.Exists(_fileLoadPath) == false)
                {
                    _steps    = ESteps.Done;
                    Status    = EStatus.Failed;
                    LastError = $"Not found assetBundle file : {_fileLoadPath}";
                    YooLogger.Error(LastError);
                    return;
                }
#endif

                // Load assetBundle file
                if (MainBundleInfo.IsEncrypted)
                {
                    if (AssetSystem.DecryptionServices == null)
                    {
                        throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {MainBundleInfo.BundleName}");
                    }

                    ulong offset = AssetSystem.DecryptionServices.GetFileOffset();
                    if (_isWaitForAsyncComplete)
                    {
                        CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath, 0, offset);
                    }
                    else
                    {
                        _cacheRequest = AssetBundle.LoadFromFileAsync(_fileLoadPath, 0, offset);
                    }
                }
                else
                {
                    if (_isWaitForAsyncComplete)
                    {
                        CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath);
                    }
                    else
                    {
                        _cacheRequest = AssetBundle.LoadFromFileAsync(_fileLoadPath);
                    }
                }
                _steps = ESteps.CheckFile;
            }

            // 4. 检测AssetBundle加载结果
            if (_steps == ESteps.CheckFile)
            {
                if (_cacheRequest != null)
                {
                    if (_isWaitForAsyncComplete)
                    {
                        // 强制挂起主线程(注意:该操作会很耗时)
                        YooLogger.Warning("Suspend the main thread to load unity bundle.");
                        CacheBundle = _cacheRequest.assetBundle;
                    }
                    else
                    {
                        if (_cacheRequest.isDone == false)
                        {
                            return;
                        }
                        CacheBundle = _cacheRequest.assetBundle;
                    }
                }

                // Check error
                if (CacheBundle == null)
                {
                    _steps    = ESteps.Done;
                    Status    = EStatus.Failed;
                    LastError = $"Failed to load assetBundle : {MainBundleInfo.BundleName}";
                    YooLogger.Error(LastError);
                }
                else
                {
                    _steps = ESteps.Done;
                    Status = EStatus.Succeed;
                }
            }
        }