protected virtual void SendWebRequest(string path) { UnityWebRequest request = new UnityWebRequest(path, UnityWebRequest.kHttpVerbGET, new DownloadHandlerBuffer(), null); if (m_Timeout > 0) { request.timeout = m_Timeout; } m_PI.ResourceManager.WebRequestOverride?.Invoke(request); m_RequestQueueOperation = WebRequestQueue.QueueRequest(request); if (m_RequestQueueOperation.IsDone) { m_RequestOperation = m_RequestQueueOperation.Result; if (m_RequestOperation.isDone) { RequestOperation_completed(m_RequestOperation); } else { m_RequestOperation.completed += RequestOperation_completed; } } else { m_RequestQueueOperation.OnComplete += asyncOperation => { m_RequestOperation = asyncOperation; m_RequestOperation.completed += RequestOperation_completed; }; } }
public IEnumerator WebRequestQueue_CompletesAllOperations() { int numberOfCompletedOperations = 0; int totalOperations = 5000; for (int i = 0; i < totalOperations; i++) { UnityWebRequest uwr = new UnityWebRequest(); var requestOp = WebRequestQueue.QueueRequest(uwr); if (requestOp.IsDone) { numberOfCompletedOperations++; } else { requestOp.OnComplete += op => { numberOfCompletedOperations++; } }; } while (WebRequestQueue.s_QueuedOperations.Count > 0) { yield return(null); } Assert.AreEqual(totalOperations, numberOfCompletedOperations); }
private void BeginOperation() { string path = m_ProvideHandle.Location.InternalId; if (File.Exists(path)) { m_RequestOperation = AssetBundle.LoadFromFileAsync(path, m_Options == null ? 0 : m_Options.Crc); m_RequestOperation.completed += LocalRequestOperationCompleted; } else if (ResourceManagerConfig.ShouldPathUseWebRequest(path)) { var req = CreateWebRequest(m_ProvideHandle.Location); req.disposeDownloadHandlerOnDispose = false; m_WebRequestQueueOperation = WebRequestQueue.QueueRequest(req); if (m_WebRequestQueueOperation.IsDone) { m_RequestOperation = m_WebRequestQueueOperation.Result; m_RequestOperation.completed += WebRequestOperationCompleted; } else { m_WebRequestQueueOperation.OnComplete += asyncOp => { m_RequestOperation = asyncOp; m_RequestOperation.completed += WebRequestOperationCompleted; }; } } else { m_RequestOperation = null; m_ProvideHandle.Complete <AssetBundleResource>(null, false, new Exception(string.Format("Invalid path in AssetBundleProvider: '{0}'.", path))); } }
public void Start(ProvideHandle provideHandle, TextDataProvider rawProvider, bool ignoreFailures) { m_PI = provideHandle; provideHandle.SetProgressCallback(GetPercentComplete); m_Provider = rawProvider; m_IgnoreFailures = ignoreFailures; var path = m_PI.ResourceManager.TransformInternalId(m_PI.Location); if (File.Exists(path)) { #if NET_4_6 if (path.Length >= 260) { path = @"\\?\" + path; } #endif var text = File.ReadAllText(path); object result = m_Provider.Convert(m_PI.Type, text); m_PI.Complete(result, result != null, result == null ? new Exception($"Unable to load asset of type {m_PI.Type} from location {m_PI.Location}.") : null); } else if (ResourceManagerConfig.ShouldPathUseWebRequest(path)) { UnityWebRequest request = new UnityWebRequest(path, UnityWebRequest.kHttpVerbGET, new DownloadHandlerBuffer(), null); m_RequestQueueOperation = WebRequestQueue.QueueRequest(request); if (m_RequestQueueOperation.IsDone) { m_RequestOperation = m_RequestQueueOperation.Result; if (m_RequestOperation.isDone) { RequestOperation_completed(m_RequestOperation); } else { m_RequestOperation.completed += RequestOperation_completed; } } else { m_RequestQueueOperation.OnComplete += asyncOperation => { m_RequestOperation = asyncOperation; m_RequestOperation.completed += RequestOperation_completed; }; } } else { Exception exception = null; //Don't log errors when loading from the persistentDataPath since these files are expected to not exist until created if (!m_IgnoreFailures) { exception = new Exception(string.Format("Invalid path in " + nameof(TextDataProvider) + " : '{0}'.", path)); } m_PI.Complete <object>(null, m_IgnoreFailures, exception); } }
public void LoadCatalogFromBundleAsync() { //Debug.Log($"LoadCatalogFromBundleAsync frame : {Time.frameCount}"); if (m_OpInProgress) { Addressables.LogError($"Operation in progress : A catalog is already being loaded. Please wait for the operation to complete."); return; } m_OpInProgress = true; if (ResourceManagerConfig.ShouldPathUseWebRequest(m_BundlePath)) { var req = UnityWebRequestAssetBundle.GetAssetBundle(m_BundlePath); if (m_WebRequestTimeout > 0) { req.timeout = m_WebRequestTimeout; } m_WebRequestQueueOperation = WebRequestQueue.QueueRequest(req); if (m_WebRequestQueueOperation.IsDone) { m_RequestOperation = m_WebRequestQueueOperation.Result; if (m_RequestOperation.isDone) { WebRequestOperationCompleted(m_RequestOperation); } else { m_RequestOperation.completed += WebRequestOperationCompleted; } } else { m_WebRequestQueueOperation.OnComplete += asyncOp => { m_RequestOperation = asyncOp; m_RequestOperation.completed += WebRequestOperationCompleted; }; } } else { m_LoadBundleRequest = AssetBundle.LoadFromFileAsync(m_BundlePath); m_LoadBundleRequest.completed += loadOp => { if (loadOp is AssetBundleCreateRequest createRequest && createRequest.assetBundle != null) { m_CatalogAssetBundle = createRequest.assetBundle; m_LoadTextAssetRequest = m_CatalogAssetBundle.LoadAllAssetsAsync <TextAsset>(); if (m_LoadTextAssetRequest.isDone) { LoadTextAssetRequestComplete(m_LoadTextAssetRequest); } m_LoadTextAssetRequest.completed += LoadTextAssetRequestComplete; }
protected override void BeginOperationImpl(UnityWebRequest request) { m_WebRequestQueueOperation = WebRequestQueue.QueueRequest(request); if (m_WebRequestQueueOperation.IsDone) { OnQueueOperationCompleted(m_WebRequestQueueOperation.Result); return; } m_WebRequestQueueOperation.OnComplete += OnQueueOperationCompleted; }
private void BeginOperation() { Debug.LogFormat("[{0}.{1}] location={2}", nameof(WebRequestBundleResource), nameof(BeginOperation), provideHandle.Location); var req = CreateWebRequest(provideHandle.Location); req.disposeDownloadHandlerOnDispose = false; webRequestQueueOperation = WebRequestQueue.QueueRequest(req); if (webRequestQueueOperation.IsDone) { OnQueueOperationCompleted(webRequestQueueOperation.Result); return; } webRequestQueueOperation.OnComplete += OnQueueOperationCompleted; }