Version: 2020.2
Method group is Obsolete

WWW

class in UnityEngine

/

继承自:CustomYieldInstruction

切换到手册
Obsolete

描述

用于方便地访问网页。

Obsolete: WWW has been replaced with UnityWebRequest.

这是一个用于检索 URL 内容的小型 utility 模块。

可以通过调用 WWW(url)(返回一个新的 WWW 对象)在后台启动下载。

您可以检查 isDone 属性以查看下载是否完成, 或通过 yield 方式自动等待下载对象(不阻塞游戏的其余部分)。

如果您需要从 Web 服务器获取一些数据来与游戏集成 (例如,实现分数排行榜或基于某种原因需要回传信息),则可以使用该类。此外,该类还有一些其他功能,例如: 使用从 Web 下载的图像创建纹理, 流式传输和加载新的 Web 播放器数据文件。

WWW 类可用于向服务器发送 GET 和 POST 请求。WWW 类默认使用 GET; 如果您提供了 postData 参数,则 WWW 类使用 POST。

另请参阅:WWWForm - 一种为 postData 参数构建有效表单数据的方法。

注意:传递给 WWW 类的 URL 必须经过“%”转义处理。

注意:在 iPhone 上,支持 http://,、https://file:// 协议。 ftp:// 协议支持仅限于匿名下载。不支持其他协议。

注意:在 Windows 和 Windows 应用商店应用程序中使用文件协议访问本地文件时,必须指定 file:///(带有三个斜杠)。

// Get the Unity logo as a texture from the Unity website
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public string url = "https://unity3d.com/files/images/ogimg.jpg"; IEnumerator Start() { using (WWW www = new WWW(url)) { yield return www; Renderer renderer = GetComponent<Renderer>(); renderer.material.mainTexture = www.texture; } } }

继承的成员

变量

keepWaiting指示协同程序是否应保持暂停。