public void loadImageTrigger(string imageURL, WebRequest.UnityWebRequestEvent OnLoadImageComplete) { var req = UnityWebRequest.GetTexture(url + "/" + container[SceneManager.GetActiveScene().name] + imageURL); req.SetRequestHeader("X-Auth-Token", authToken); webRequest.SendUnityWebRequest(req, OnLoadImageComplete); }
IEnumerator GetTexture() { url = urlInput.text; Renderer renderer = GetComponent <Renderer>(); //ServicePointManager.ServerCertificateValidationCallback = TrustCertificate; // =============== /*HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + url + "/stream"); * request.ContentType = "image/jpg"; * request.PreAuthenticate = true; * request.Credentials = new NetworkCredential ("Robot","@213R0b0T"); * request.Method = "GET";*/ // ^^^ // Combine // vvv UnityWebRequest www = UnityWebRequest.GetTexture("http://" + url + ":8080/?action=snapshot"); yield return(www.Send()); requested += -1; renderer.material.mainTexture = ((DownloadHandlerTexture)www.downloadHandler).texture; // =============== // This is to get a responce - still haven't figured it out... /*HttpWebResponse response = (HttpWebResponse) request.GetResponse(); * Stream dataStream = response.GetResponseStream (); * StreamReader reader = new StreamReader (dataStream); * string responseFromServer = reader.ReadToEnd (); * * Debug.Log ("responseFromServer=" + responseFromServer );*/ }
/// <summary> /// Initiates the image. /// </summary> /// <returns>Wait for complete.</returns> /// <param name="path">Image path.</param> /// <param name="ojName">Object name.</param> /// <param name="oj">GameObject which you want to store the image object in.</param> public IEnumerator initiateImage(string path, string ojName, GameObject oj) { mycallback.onLoadStart("Start initiating: " + path); try { request = UnityWebRequest.GetTexture(path); } catch (Exception e) { mycallback.onLoadFailed("Initiate Error: " + e); } AsyncOperation ao = request.Send(); while (!ao.isDone) { mycallback.getInitiatePorgress(request.downloadProgress, ojName); yield return(new WaitForEndOfFrame()); } yield return(request.isDone == true); if (request.isError) { mycallback.onLoadFailed("Initiate Error"); } else { _initiateImage(ojName, oj); } }
private IEnumerator UpdateEnvironmentMapRoutine() { UnityWebRequest request = UnityWebRequest.GetTexture(URL); yield return(request.Send()); if (request.responseCode == 200) { UpdateObserverRotation(); UpdateTexture(request.downloadHandler.data); switch (IBLType) { case IBLTypes.ReflectionProbe: ReflectionProbe.RenderProbe(); break; case IBLTypes.Skyshop: RenderToCubemap(); UpdateSphericalHarmonics(); break; default: break; } Resources.UnloadUnusedAssets(); } else if (request.isError) { Debug.Log(request.error); } }
/// <summary> /// Downloads the Person's Avatar as a Texture from the Url. /// </summary> /// <param name="success">True if the download succeeded.</param> /// <param name="force">Optional: Force the texture to be redownloaded.</param> public IEnumerator Download(Action <bool> success, bool force = false) { if (Downloaded && !force) { success(Texture); } else { var www = UnityWebRequest.GetTexture(Uri.AbsoluteUri); yield return(www.Send()); if (www.isError) { Debug.LogError("Failed to Download Avatar: " + www.error); success(false); } else { var tex = ((DownloadHandlerTexture)www.downloadHandler).texture; if (tex) { Texture = tex; Downloaded = true; success(true); } else { // TODO: Find out if this can happen. Debug.LogError("Failed. Check Implementation"); throw new NotSupportedException(www.downloadHandler.text); } } } }
private IEnumerator GetImage(string url) { UnityWebRequest request = UnityWebRequest.GetTexture(url); yield return(request.Send()); if (request.isError) { Debug.Log("Error downloading image"); Debug.Log(request.error); } else { Debug.Log("Loaded image"); Texture2D texture = ((DownloadHandlerTexture)request.downloadHandler).texture; if (texture == null) { Debug.Log("Image is null"); } else { thumbnailLoading.SetActive(false); thumbnail.SetActive(true); Rect rect = new Rect(0, 0, texture.width, texture.height); Sprite newSprite = Sprite.Create(texture, rect, Vector2.zero); thumbnailImage.sprite = newSprite; thumbnailImage.preserveAspect = true; } } }
IEnumerator asyncLoad(string imgName) { string url = globalData.url; url = url + globalData.getUnixPath() + "/" + imgName + ".jpg" + "?p=" + globalData.sessionId; UnityWebRequest www = UnityWebRequest.GetTexture(url); www.SetRequestHeader("AUTHORIZATION", globalData.getHeader()); yield return(www.Send()); print(url); if (www.responseCode == 404) { url = globalData.url + globalData.getUnixPath() + "/" + imgName + ".png" + "?p=" + globalData.sessionId; www = UnityWebRequest.GetTexture(url); www.SetRequestHeader("AUTHORIZATION", globalData.getHeader()); yield return(www.Send()); } if (www.isError) { Debug.Log("Error accessing the url : " + url + " : " + www.error); } else { DestroyImmediate(mat); mat = new Material(Shader.Find("Sprites/Default")); mat.mainTexture = ((DownloadHandlerTexture)www.downloadHandler).texture; img.material = mat; } print(url); www.Dispose(); fLoaded = true; }
public static UnityWebRequest GetTextureRequest(string url) { #if UNITY_2017_1_OR_NEWER return(UnityWebRequestTexture.GetTexture(url)); #else return(UnityWebRequest.GetTexture(url)); #endif }
public static UnityWebRequest GetTexture(string url) { #if UNITY_2017_1_OR_NEWER // New API. return(UnityWebRequestTexture.GetTexture(url)); #else // Old API, removed in Unity 2017.1. return(UnityWebRequest.GetTexture(url)); #endif }
/// <summary> /// Setup request. /// </summary> public void Setup() { // Determine which request to use. switch (requestInfo.RequestType) { case Netko.RequestType.Get: UnityRequest = UnityWebRequest.Get(requestInfo.Url.GetUriEscaped()); break; case Netko.RequestType.Post: UnityRequest = UnityWebRequest.Post(requestInfo.Url.GetUriEscaped(), requestInfo.Form); if (requestInfo.UploadHandler != null) { UnityRequest.uploadHandler = requestInfo.UploadHandler; } break; case Netko.RequestType.Delete: UnityRequest = UnityWebRequest.Delete(requestInfo.Url.GetUriEscaped()); break; case Netko.RequestType.Put: UnityRequest = UnityWebRequest.Put(requestInfo.Url.GetUriEscaped(), requestInfo.PutData); break; case Netko.RequestType.Head: UnityRequest = UnityWebRequest.Head(requestInfo.Url.GetUriEscaped()); break; case Netko.RequestType.Audio: UnityRequest = UnityWebRequest.GetAudioClip(requestInfo.Url.GetUriEscaped(), requestInfo.AudioType); break; case Netko.RequestType.AudioStream: AudioRequest = new AudioStreamRequest(requestInfo.Url.GetUriEscaped(true)); break; case Netko.RequestType.Texture: UnityRequest = UnityWebRequest.GetTexture( requestInfo.Url.GetUriEscaped(), requestInfo.TextureNonReadable ); break; case Netko.RequestType.AssetBundle: UnityRequest = UnityWebRequest.GetAssetBundle( requestInfo.Url.GetUriEscaped(), requestInfo.AssetBundleVersion, requestInfo.AssetBundleCRC ); break; } // Initialize variables SetError(null); isProcessing = false; TimeOutTime = requestInfo.TimeOut; }
/// <summary> /// Creates an asyncronous operation optimized for downloading a <see cref="Texture2D"/> via HTTP GET. /// </summary> /// <param name="url">The URI of the texture to download.</param> /// <param name="nonReadable">If <see langword="true"/>, the texture's raw data will not be accessible to script. This can conserve memory.</param> /// <returns>An operation that can be used to track the download process.</returns> public static IAsyncOperation <Texture2D> GetTexture(string url, bool nonReadable) { #if UNITY_2017_1_OR_NEWER var webRequest = UnityWebRequestTexture.GetTexture(url, nonReadable); var result = new Helpers.WebRequestResult <Texture2D>(webRequest); #else var webRequest = UnityWebRequest.GetTexture(url, nonReadable); var result = new Helpers.WebRequestResult <Texture2D>(webRequest); #endif result.Start(); return(result); }
private IEnumerator DownLoadHeadIcon() { if (headIcon != null && headIcon != "") { UnityWebRequest www = UnityWebRequest.GetTexture(headIcon); yield return(www.Send()); texture2D = ((DownloadHandlerTexture)www.downloadHandler).texture; Sprite tempSp = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), new Vector2(0, 0)); headIconImg.sprite = tempSp; GlobalDataScript.imageMap.Add(headIcon, tempSp); } }
/// <summary> /// Creates an asyncronous operation optimized for downloading a <see cref="Texture2D"/> via HTTP GET. /// </summary> /// <param name="url">The URI of the texture to download.</param> /// <param name="nonReadable">If <see langword="true"/>, the texture's raw data will not be accessible to script. This can conserve memory.</param> /// <param name="userState">User-defined data.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="url"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentException">Thrown if <paramref name="url"/> is an empty string.</exception> /// <returns>An operation that can be used to track the download process.</returns> /// <seealso cref="GetTextureAsync(string, object)"/> public static IAsyncOperation <Texture2D> GetTextureAsync(string url, bool nonReadable, object userState = null) { ThrowIfInvalidUrl(url); #if UNITY_2017_1_OR_NEWER var webRequest = UnityWebRequestTexture.GetTexture(url, nonReadable); #else var webRequest = UnityWebRequest.GetTexture(url, nonReadable); #endif var result = new Helpers.WebRequestResult <Texture2D>(webRequest, userState); result.Start(); return(result); }
IEnumerator Start() { observerIsRunning = false; EnvironmentMapSphere.SetActive(false); UnityWebRequest request = UnityWebRequest.GetTexture(URL); request.timeout = 3; yield return(request.Send()); if (request.responseCode != 200) { switch (IBLType) { case IBLTypes.ReflectionProbe: ReflectionProbe.RenderProbe(); break; case IBLTypes.Skyshop: RenderToCubemap(); UpdateSphericalHarmonics(); break; default: break; } yield break; } DefaultEnvironmentMapSphere.SetActive(false); EnvironmentMapSphere.SetActive(true); targetRenderer = EnvironmentMapSphere.GetComponent <Renderer>(); texture = new Texture2D(2, 2); imageBytes = new List <byte>(); mainCamera = Camera.main; if ((IBLType == IBLTypes.ReflectionProbe) && (ReflectionProbe != null)) { observerIsRunning = true; } #if SKYSHOP else if ((IBLType == IBLTypes.Skyshop) && (EnvironmentCubemap != null) && (Sky != null)) { observerIsRunning = true; } #endif }
public IEnumerator LoadImageURL(string url) { UnityWebRequest www = UnityWebRequest.GetTexture(url); yield return(www.Send()); if (www.isError) { Debug.Log("Failed to load image: " + url); } else { Texture texture = ((DownloadHandlerTexture)www.downloadHandler).texture; } }
public IEnumerator LoadImageURL(string url) { UnityWebRequest www = UnityWebRequest.GetTexture(url); yield return(www.Send()); if (www.isError) { Log.Text(label, "Failed to load image: " + url, www.error, Log.Level.Error); } else { Texture texture = ((DownloadHandlerTexture)www.downloadHandler).texture; ChangeImage(texture); } }
IEnumerator GetText() { UnityWebRequest www = UnityWebRequest.GetTexture("http://lightnarcissus.com/wp-content/uploads/2015/10/trialogue_paintitblack-1024x573.png"); yield return(www.Send()); if (www.isError) { Debug.Log(www.error); } else { // Show results as text quad.GetComponent <Renderer> ().material.mainTexture = ((DownloadHandlerTexture)www.downloadHandler).texture; } }
public IEnumerator GetTexture(string imageUri) { using (var request = UnityWebRequest.GetTexture(imageUri)) { yield return(request.Send()); if (request.isError) { Debug.Log(request.error); } else { ResponsedTexture = ((DownloadHandlerTexture)(request.downloadHandler)).texture; } yield return(ResponsedTexture); } }
/// <summary> /// Creates an asyncronous operation optimized for downloading a <see cref="Texture2D"/> via HTTP GET. /// </summary> /// <param name="url">The URI of the texture to download.</param> /// <param name="nonReadable">If <see langword="true"/>, the texture's raw data will not be accessible to script. This can conserve memory.</param> /// <returns>An operation that can be used to track the download process.</returns> public static IAsyncOperation <Texture2D> GetTexture(string url, bool nonReadable) { #if UNITY_2017 || UNITY_2018 var webRequest = UnityWebRequestTexture.GetTexture(url, nonReadable); var result = new WebRequestResult <Texture2D>(webRequest); #elif UNITY_5_4_OR_NEWER var webRequest = UnityWebRequest.GetTexture(url, nonReadable); var result = new WebRequestResult <Texture2D>(webRequest); #else var www = new WWW(url); var result = new WwwResult <Texture2D>(www); #endif result.Start(); return(result); }
private IEnumerator LoadPhotoTexture(Photo photo) { var queryString = string.Format("photoreference={0}&key={1}&maxwidth=800" , photo.photo_reference, PlacesAPIKey); var url = GOOGLE_DETAIL_PHOTO_URL + "?" + queryString; var req = UnityWebRequest.GetTexture(url); //yield until the service responds yield return(req.Send()); //first destroy the old texture first Destroy(photoRenderer.material.mainTexture); //when the image returns set it as the tile texture photoRenderer.material.mainTexture = ((DownloadHandlerTexture)req.downloadHandler).texture; }
/// <summary> /// Creates an asyncronous operation optimized for downloading a <see cref="Texture2D"/> via HTTP GET. /// </summary> /// <param name="url">The URI of the texture to download.</param> /// <returns>An operation that can be used to track the download process.</returns> public static IAsyncOperation <Texture2D> GetTexture(string url) { #if UNITY_2017_1_OR_NEWER var webRequest = UnityWebRequestTexture.GetTexture(url, false); var result = new Helpers.WebRequestResult <Texture2D>(webRequest); #elif UNITY_5_4_OR_NEWER var webRequest = UnityWebRequest.GetTexture(url); var result = new Helpers.WebRequestResult <Texture2D>(webRequest); #else var www = new WWW(url); var result = new Helpers.WwwResult <Texture2D>(www); #endif result.Start(); return(result); }
IEnumerator LoadTexture() { var queryString = string.Format("location={0}&fov={1}&heading={2}&key={3}&size={4}x{5}&pitch={6}" , location.LatLong, fov, heading, MapsAPIKey, size.x, size.y, pitch); var req = UnityWebRequest.GetTexture(GOOGLE_STREET_VIEW_URL + "?" + queryString); //yield until the service responds yield return(req.Send()); //first destroy the old texture first Destroy(GetComponent <RawImage>().material.mainTexture); //when the image returns set it as the tile texture GetComponent <RawImage>().texture = ((DownloadHandlerTexture)req.downloadHandler).texture; GetComponent <RawImage>().material.mainTexture = ((DownloadHandlerTexture)req.downloadHandler).texture; }
private IEnumerator ProcessImageRequest(string endpoint, ImageEvent onSuccess) { using (UnityWebRequest www = UnityWebRequest.GetTexture(imageBaseUri + endpoint + baseArgs, true)) { yield return(www.Send()); //if(www.isNetworkError || www.isHttpError) { if (www.isError) { onError.Invoke(www.error); } else { onSuccess.Invoke(DownloadHandlerTexture.GetContent(www)); } } }
void m_Start() { var type = cRequest.assetType; var userData = cRequest.uploadData; if (LoaderType.Typeof_AssetBundle.Equals(type)) { m_webrequest = UnityWebRequest.GetAssetBundle(cRequest.url); } if (LoaderType.Typeof_Texture2D.Equals(type)) { #if UNITY_2017 m_webrequest = UnityWebRequestTexture.GetTexture(cRequest.url); #else m_webrequest = UnityWebRequest.GetTexture(cRequest.url); #endif } else if (userData is WWWForm) { m_webrequest = UnityWebRequest.Post(cRequest.url, (WWWForm)userData); } else if (userData is string) { var bytes = LuaHelper.GetBytes(userData.ToString()); m_webrequest = UnityWebRequest.Put(cRequest.url, bytes); } else if (userData is System.Array) { m_webrequest = UnityWebRequest.Put(cRequest.url, (byte[])userData); } else { m_webrequest = UnityWebRequest.Get(cRequest.url); } System.Net.WebHeaderCollection headers = cRequest.webHeader; if (headers != null) { foreach (var k in headers.AllKeys) { m_webrequest.SetRequestHeader(k, headers.Get(k)); } } m_asyncOperation = m_webrequest.Send(); }
IEnumerator loadTxtLines() { string strAllText; string url = globalData.url; string fileName; if (SceneManager.GetActiveScene().name == "ListLevel") { //if (globalData.getCategory () == "") fileName = "menuConfig.txt"; } else if (SceneManager.GetActiveScene().name == "LogIn") { fileName = "userList.csv"; } else { fileName = globalData.getUnixPath() + "/" + "cardConfig.txt"; } url = url + fileName + "?p=" + globalData.sessionId; string authorization = authenticate("hadmin", "hindiusa123"); UnityWebRequest www = UnityWebRequest.GetTexture(url); www.SetRequestHeader("AUTHORIZATION", authorization); yield return(www.Send()); if (www.responseCode == 403) { print("Unauthorized!"); } if (www.isError) { Debug.Log("Error accessing the url : " + url + " : " + www.error); } else { strAllText = www.downloadHandler.text; lstLines = new List <string>(strAllText.Split(new string[] { "\r", "\n" }, System.StringSplitOptions.RemoveEmptyEntries)); print(strAllText); } print(url); www.Dispose(); fLoaded = true; }
IEnumerator GetTextureWeb() { UnityWebRequest www = UnityWebRequest.GetTexture("http://www.telescope.com/assets/images/starcharts/2016-11-starchart_col.png"); yield return(www.Send()); if (www.isError) { Debug.Log(www.error); } else { myTexture = ((DownloadHandlerTexture)www.downloadHandler).texture; GetComponent <Renderer> ().material.mainTexture = myTexture; } }
IEnumerator GetTextureWeb() { UnityWebRequest www = UnityWebRequest.GetTexture("http://people.duke.edu/~mwo4/kioskScreenSavr.png"); yield return(www.Send()); if (www.isError) { Debug.Log(www.error); } else { myTexture = ((DownloadHandlerTexture)www.downloadHandler).texture; GetComponent <Renderer> ().material.mainTexture = myTexture; } }
public IEnumerator DownLoadAssetBundle(string url, Action <AssetBundle> callback) { using (var www = UnityWebRequest.GetTexture(url)) { AssetBundle assetbundle = null; yield return(www.Send()); if (!www.isError && www.responseCode != 404) { assetbundle = DownloadHandlerAssetBundle.GetContent(www); } if (callback != null) { callback.Invoke(assetbundle); } } }
/// <summary> /// テスクチャをWebからロードします(コルーチン). /// </summary> IEnumerator Co_GetTexture(string url) { _request = UnityWebRequest.GetTexture(url); // _request.disposeDownloadHandlerOnDispose = false; yield return(_request.Send()); if (!_request.isError) { m_ImageIcon.texture = (_request.downloadHandler as DownloadHandlerTexture).texture; } else { Debug.LogError(_request.error); } _request.Dispose(); _request = null; }
private void _BeginDownload() { m_Data = null; var type = cRequest.assetType; var head = cRequest.head; if (CacheManager.Typeof_AudioClip.Equals(type)) { AudioType au = AudioType.MOD; if (cRequest.head is AudioType) { au = (AudioType)cRequest.head; } m_webrequest = UnityWebRequest.GetAudioClip(cRequest.url, au); } else if (CacheManager.Typeof_Texture2D.Equals(type)) { if (cRequest.head is bool) { m_webrequest = UnityWebRequest.GetTexture(cRequest.url, (bool)cRequest.head); } else { m_webrequest = UnityWebRequest.GetTexture(cRequest.url); } } else if (head is WWWForm) { m_webrequest = UnityWebRequest.Post(cRequest.url, (WWWForm)head); } else if (head is string) { var bytes = LuaHelper.GetBytes(head.ToString()); m_webrequest = UnityWebRequest.Put(cRequest.url, bytes); } else if (head is System.Array) { m_webrequest = UnityWebRequest.Put(cRequest.url, (byte[])head); } else { m_webrequest = UnityWebRequest.Get(cRequest.url); } m_asyncOperation = m_webrequest.Send(); }