用于方便地访问网页。
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 | 指示协同程序是否应保持暂停。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.