public bool CancelTask(string bundleName) { for (int i = 0; i < _taskList.Count; i++) { if (_taskList[i].bundleName == bundleName) { if (_taskList[i].state == GameResDownloadState.WAITING) { _taskList.RemoveAt(i); return(true); } if (_taskList[i].state == GameResDownloadState.DOWNLOADING) { StopAllCoroutines(); if (_curWebRequest != null) { GameWebRequest.DestroyAssetBundleWebRequest(_curWebRequest); _curWebRequest = null; } _taskList[i].state = GameResDownloadState.CANCEL; OnDownloadFinish(_taskList[i]); return(true); } _taskList[i].onDownloadState = null; } } return(false); }
public RegisterHandler(string newGUID, string newPassword) { request = new GameWebRequest(HttpMethod.Post, "account/register"); request.AddQuery("guid", newGUID); request.AddQuery("newGUID", newGUID); request.AddQuery("newPassword", newPassword); }
public VerifyAgeHandler(string guid, string password) { request = new GameWebRequest(HttpMethod.Post, "account/verifyage"); request.AddQuery("guid", guid); request.AddQuery("password", password); request.AddQuery("isAgeVerified", "1"); }
private void Awake() { init = new GameWebRequest(HttpMethod.Post, "app/init"); button.interactable = true; button.onClick.AddListener(() => { init.OnRequest(); Debug.LogWarningFormat("Response from AppEngine request '{0}':\n{1}", init.request, init.OnResponse()); }); }
void OnEnable() { if (string.IsNullOrEmpty(mData)) { if (PlayerProfile.allowedToAccessInternet) { GameWebRequest.Create(url, OnFinished); } else { mLabel.text = Localization.Get("Wifi Required"); } } }
public void CancelAll() { for (int i = 0; i < _taskList.Count; i++) { _taskList[i].onDownloadState = null; } _taskList.Clear(); StopAllCoroutines(); if (_curWebRequest != null) { GameWebRequest.DestroyAssetBundleWebRequest(_curWebRequest); _curWebRequest = null; } _curTask = null; }
/// <summary> /// Create a new web request for the following URL, providing the specified parameter. /// </summary> static public void Create(string url, OnFinished callback, object param) { if (Application.isPlaying) { GameObject go = new GameObject("_Game Web Request"); DontDestroyOnLoad(go); GameWebRequest req = go.AddComponent <GameWebRequest>(); #if UNITY_EDITOR Debug.Log(url); #endif req.mURL = url; req.mCallback = callback; req.mParam = param; } }
// onDownloadState 0下载完成 1下载失败 2下载中 public int Start(string bundleName, string[] urls, string hash, int totalSize, Action <int, float, int, int> onDownloadState, int timeOut = 10, bool isImmediatelyStart = true) { var task = new GameResDownloadTask() { taskId = _taskIdGenerator++, bundleName = bundleName, hash = hash, urls = urls, totalSize = totalSize, onDownloadState = onDownloadState, timeOut = timeOut, state = GameResDownloadState.WAITING, }; if (isImmediatelyStart || _taskList.Count == 0) { _taskList.Insert(0, task); StopAllCoroutines(); if (_curTask != null) { _curTask.state = GameResDownloadState.WAITING; _curTask = null; } if (_curWebRequest != null) { GameWebRequest.DestroyAssetBundleWebRequest(_curWebRequest); _curWebRequest = null; } StartCoroutine(_DownloadAsync(task)); } else { _taskList.Add(task); } return(task.taskId); }
private IEnumerator LoadAssetBundleFromCache(Dictionary <string, GameResAssetBundle> bundleGroupMap, string bundleName, string manifestName, string hash, string[] urls, System.Action <bool> onLoadDone) { var realHash = Hash128.Parse(hash); bool success = false; foreach (string url in urls) { float checkTimeOutTime = Time.time; float progress = 0; var webRequest = GameWebRequest.SendAssetBundleWebRequest(url, realHash, true); while (!webRequest.request.isDone) { if (!string.IsNullOrEmpty(webRequest.request.error)) { break; } if (progress != webRequest.request.downloadProgress) { checkTimeOutTime = Time.time; } else if (Time.time - checkTimeOutTime >= 5) { break; } yield return(null); } if (!string.IsNullOrEmpty(webRequest.request.error) || !webRequest.request.isDone) { FTDebug.LogWarning(string.Format("Failed To LoadAssetBundleFromCache Name[{0}] From[{1}] Error[{2}]", bundleName, url, webRequest.request.error)); GameWebRequest.DestroyAssetBundleWebRequest(webRequest); Caching.ClearCachedVersion(bundleName, realHash); continue; } AssetBundle assetBundle = null; try { assetBundle = DownloadHandlerAssetBundle.GetContent(webRequest.request); if (assetBundle == null) { FTDebug.LogWarning(string.Format("Failed To LoadAssetBundleFromCache Name[{0}] From[{1}] Error[AssetBundle is Null]", bundleName, url)); GameWebRequest.DestroyAssetBundleWebRequest(webRequest); Caching.ClearCachedVersion(bundleName, realHash); continue; } } catch (System.Exception e) { FTDebug.LogWarning(string.Format("Failed To LoadAssetBundleFromCache Name[{0}] From[{1}] Error[{2}]", bundleName, url, e.Message)); GameWebRequest.DestroyAssetBundleWebRequest(webRequest); Caching.ClearCachedVersion(bundleName, realHash); continue; } if (bundleGroupMap.ContainsKey(bundleName) && bundleGroupMap[bundleName].hash != hash) { UnLoadAssetBundle(bundleName, manifestName); } if (!bundleGroupMap.ContainsKey(bundleName)) { bundleGroupMap.Add(bundleName, new GameResAssetBundle() { hash = hash, assetBundle = assetBundle, }); } GameWebRequest.DestroyAssetBundleWebRequest(webRequest); success = true; FTDebug.Log(string.Format("LoadAssetBundleFromCache Name[{0}] From[{1}]", bundleName, url)); // 清除除当前使用的 Caching.ClearOtherCachedVersions(bundleName, realHash); break; } onLoadDone(success); }
public CharListHandler(string guid, string password) { request = new GameWebRequest(HttpMethod.Post, "char/list"); request.AddQuery("guid", guid); request.AddQuery("password", password); }
private IEnumerator _DownloadAsync(GameResDownloadTask task) { _curTask = task; var realHash = Hash128.Parse(task.hash); task.state = GameResDownloadState.DOWNLOADING; #if UNITY_ANDROID && !UNITY_EDITOR Caching.compressionEnabled = !task.bundleName.Contains("video"); #endif bool success = false; foreach (string url in task.urls) { float checkTimeOutTime = Time.time; float progress = 0; FTDebug.Log(string.Format("Download {0} From {1} Size[{2}]", task.bundleName, url, task.totalSize)); _curWebRequest = GameWebRequest.SendAssetBundleWebRequest(url, realHash, true); if (task.onDownloadState != null) { task.onDownloadState((int)GameResDownloadState.DOWNLOADING, 0, 0, _taskList.Count); } while (_curWebRequest != null && !_curWebRequest.request.isDone) { if (!string.IsNullOrEmpty(_curWebRequest.request.error)) { break; } var _progress = _curWebRequest.request.downloadProgress; if (task.timeOut != 0) { if (progress != _progress) { checkTimeOutTime = Time.time; } else if (Time.time - checkTimeOutTime >= task.timeOut) { break; } } if (progress != _progress && task.onDownloadState != null) { task.onDownloadState((int)GameResDownloadState.DOWNLOADING, _progress, (int)(_progress * task.totalSize), _taskList.Count); } progress = _progress; yield return(null); } FTDebug.LogWarning(string.Format("Download Result {0} From {1} Error[{2}] {3}", task.bundleName, url, _curWebRequest.request.error, _curWebRequest.request.isDone)); if (!string.IsNullOrEmpty(_curWebRequest.request.error) || !_curWebRequest.request.isDone) { FTDebug.LogWarning(string.Format("Failed To Download {0} From {1} Error[{2}]", task.bundleName, url, _curWebRequest.request.error)); GameWebRequest.DestroyAssetBundleWebRequest(_curWebRequest); _curWebRequest = null; continue; } FTDebug.Log(string.Format("Download Success {0} From {1} Size[{2}]", task.bundleName, url, task.totalSize)); GameWebRequest.DestroyAssetBundleWebRequest(_curWebRequest); _curWebRequest = null; success = true; break; } #if UNITY_ANDROID && !UNITY_EDITOR if (!Caching.compressionEnabled) { Caching.compressionEnabled = true; } #endif task.state = success ? GameResDownloadState.SUCCESS : GameResDownloadState.FAILED; OnDownloadFinish(task); }