Version: 2019.2
public static Networking.UnityWebRequest GetTexture (string uri);
public static Networking.UnityWebRequest GetTexture (string uri, bool nonReadable);

パラメーター

uriダウンロードするイメージの URI
nonReadableTrue の場合、テクスチャの RAW データはスクリプトにアクセスできません。これは メモリを節約することができます。デフォルト: false

戻り値

UnityWebRequest [UnityWebRequest]] は イメージをダウンロードするために適切に設定され、イメージを Texture に変換します。

説明

HTTP GET 経由でイメージをダウンロードしようとする時に UnityWebRequest を作成し、取得したデータに基づいて Texture を作成します。

このメソッドは UnityWebRequest を作成し、string 引数の uri に対象の URL を設定します。他のフラグまたはカスタムヘッダーの設定はしません。

このメソッドは UnityWebRequestDownloadHandlerTexture オブジェクトをアタッチします。 DownloadHandlerTexture は Unity Engine のテクスチャとして使用するイメージの保存用に最適化された特別な DownloadHandler です。このクラスを使用すると、RAW バイトデータをダウンロードしてスクリプトで手動でテクスチャーを作成することに比べてメモリの再割り当てが軽減されます。また、テクスチャーの変換はワーカースレッド上で実行されます。

このメソッドは UploadHandlerUnityWebRequest にアタッチしません。

Please note that the texture will be created as if it stores color data (See Also: TextureImporter.sRGBTexture). If you need to download linear data use ImageConversion.LoadImage.

Note: Only JPG and PNG formats are supported.
Note: UnityWebRequest.GetTexture is obsolete. Use UnityWebRequestTexture.GetTexture instead.

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class MyBehaviour : MonoBehaviour { void Start() { StartCoroutine(GetText()); }

IEnumerator GetText() { using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture("http://www.my-server.com/myimage.png")) { yield return uwr.SendWebRequest();

if (uwr.isNetworkError || uwr.isHttpError) { Debug.Log(uwr.error); } else { // Get downloaded asset bundle var texture = DownloadHandlerTexture.GetContent(uwr); } } } }