WWW 网页
Inherits from IDisposable
Simple access to web pages.
简单的访问网页的类。
This is a small utility module for retrieving the contents of URLs.
这是一个检索URL内容的小工具模块。
You start a download in the background by calling WWW(url) which returns a new WWW object.
你通过连接WWW(url)在后台开始下载,并且返回一个新的WWW对象。
You can inspect the isDone property to see if the download has completed or yield the download object to automatically wait until it is (without blocking the rest of the game).
你可以检查isDone属性来查看是否已经下载完成,或者yield自动等待下载物体,直到它被下载完成(不会影响游戏的其余部分)。
Use it if you want to get some data from a web server for integration with a game such as highscore lists or calling home for some reason. There is also functionality to create textures from images downloaded from the web and to stream & load new web player data files.
如果你想从web服务器上获取一些数据,例如高分列表或者调用主页,可以使用这个,也有一些功能可以使用从web上下载的图片来创建一个纹理,或者下载或加载新的web播放器数据文件。
The WWW class can be used to send both GET and POST requests to the server. The WWW class will use GET by default and POST if you supply a postData parameter.
WWW类可以用来发送GET和POST请求到服务器,WWW类默认使用GET方法,并且如果提供一个postData参数可用POST方法。
See Also: WWWForm for a way to build valid form data for the postData parameter.
参见: WWWForm为postData参数构建可用的表单数据。
Note: http://, https:// and file:// protocols are supported on iPhone. ftp:// protocol support is limited to anonymous downloads only. Other protocols are not supported.
注意:iPhone支持http://, https:// 和 file://协议;ftp://协议的支持仅限于匿名下载。其他协议不被支持。
Note: The security sandbox present in web-player builds prevents you from accessing content not hosted the server where the webplayer is hosted.
注意:在当前的web播放器构建安全沙箱防止你访问内容没有托管服务器,在哪里web播放器被托管。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
IEnumerator Start() {
//在C#中,需要用到yield的话,必须建立在IEnumerator类中执行。
WWW www = new WWW(url);
//定义www为WWW类型并且等于所下载下来的WWW中内容。
yield return www;
//返回所下载的www的值
renderer.material.mainTexture = www.texture;
//将下载下来的WWW中的图片赋予到默认物体的材质上进行渲染出来
}
}
// Get the latest webcam shot from outside "Friday's" in Times Square
//从时代广场外部"Friday"的web摄像头获取最新的图片
var url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
//定义url为字符变量并赋予值为"http://images.earthcam.com/ec_metros/ourcams/fridays.jpg"(赋值为图片)
function Start () {
// Start a download of the given URL
//开始下载被指定的路径
var www : WWW = new WWW (url);
//定义www为WWW类型并且等于被下载的内容。
// Wait for download to complete
//等待www全部下载完毕
yield www;
//等待www完全下载。
// 指定texture
renderer.material.mainTexture = www.texture;
//将下载下来的WWW中的图片赋予到默认物体的材质上进行渲染出来
}
Variables变量
-
Returns the contents of the fetched web page as a string (Read Only).
通过网页获取并以字符串的形式返回内容(只读)。 -
Returns the contents of the fetched web page as a byte array (Read Only).
以字节组的形式返回获取到的网络页面中的内容(只读)。 -
Returns an error message if there was an error during the download (Read Only).
返回一个错误消息,在下载期间如果产生了一个错误的话。(只读) -
Returns a Texture2D generated from the downloaded data (Read Only).
从下载的数据返回生成的一个Texture2D(只读)。 -
Returns a AudioClip generated from the downloaded data (Read Only).
从下载的数据,返回一个AudioClip。(只读) -
Returns a MovieTexture generated from the downloaded data (Read Only).
从下载的数据,返回一个MovieTexture(只读)。 -
Is the download already finished? (Read Only)
判断下载是否已经完成(只读)? -
How far has the download progressed (Read Only).
下载进度有多少(只读)? -
How far has the upload progressed (Read Only).
上传进度有多少(只读) -
Load an Ogg Vorbis file into the audio clip.
加载一个Ogg Vorbis文件到音频剪辑。 -
The URL of this WWW request (Read Only).
该WWW请求的URL(只读)。 -
Streams an AssetBundle that can contain any kind of asset from the project folder.
AssetBundle的数据流,可以包含项目文件夹中的任何类型资源。 -
Priority of AssetBundle decompression thread.
AssetBundle解压缩线程的优先级。
Constructors构造器
-
Creates a WWW request with the given URL.
用给定的URL创建一个WWW请求。
Functions函数
-
Replaces the contents of an existing Texture2D with an image from the downloaded data.
利用一个从下载数据中的图像来替换现有Texture2D。 -
Loads the new web player data file.
加载新的web播放器数据文件。
Class Functions类函数
-
Encodes string into an URL-friendly format.
字符串编码成一个URL的格式。 -
Decodes string from an URL-friendly format.
从一个URL格式解码字符串。 -
Loads an assetBundle from the cache, or downloads it, in case it is not cached.
从缓存加载一个资源包,如果没有被缓存,或从下载加载。