用户工具

站点工具


侧边栏



Unity3D中文文档

script:unityengine:classes:www:www

WWW 万维网

Namespace: UnityEngine

Description 描述

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: URLs passed to WWW class must be '%' escaped.

注意,URL传递到WWW类,必须是%编码。

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:'' When using file protocol on Windows and Windows Store Apps for accessing local files, you have to specify file:///__ (with three slashes).

注意,当在windows和Windows Store Apps使用文件协议来访问本地文件,需要使用file:///(带有三个斜线)。

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播放器被托管。

JavaScript:

// Get the latest webcam shot from outside "Friday's" in Times Square
var 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);
 
// Wait for download to complete yield www;
 
// assign texture renderer.material.mainTexture = www.texture; } 

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
    IEnumerator Start() {
        WWW www = new WWW(url);
        yield return www;
        renderer.material.mainTexture = www.texture;
    }
}

Variables 变量

assetBundle Streams an AssetBundle that can contain any kind of asset from the project folder.
AssetBundle的数据流,可以包含项目文件夹中的任何类型资源。
audioClip Returns a AudioClip generated from the downloaded data (Read Only).
从下载的数据,返回一个AudioClip。(只读)
bytes Returns the contents of the fetched web page as a byte array (Read Only).
以字节组的形式返回获取到的网络页面中的内容(只读)。
bytesDownloaded The number of bytes downloaded by this WWW query (read only).
通过该WWW查询已下载的字节数(只读)。
error Returns an error message if there was an error during the download (Read Only).
返回一个错误消息,在下载期间如果产生了一个错误的话。(只读)
isDone Is the download already finished? (Read Only)
判断下载是否已经完成(只读)?
movie Returns a MovieTexture generated from the downloaded data (Read Only).
从下载的数据,返回一个MovieTexture(只读)。
progress How far has the download progressed (Read Only).
下载进度有多少(只读)?
text Returns the contents of the fetched web page as a string (Read Only).
通过网页获取并以字符串的形式返回内容(只读)。
texture Returns a Texture2D generated from the downloaded data (Read Only).
从下载的数据返回一个Texture2D(只读)。
textureNonReadable Returns a non-readable Texture2D generated from the downloaded data (Read Only).
从下载的数据返回一个非可读的Texture2D(只读)。
threadPriority Priority of AssetBundle decompression thread.
AssetBundle解压缩线程的优先级。
uploadProgress How far has the upload progressed (Read Only).
上传进度有多少(只读)。
url The URL of this WWW request (Read Only).
此WWW请求的URL(只读)。

Constructors 构造器

WWW Creates a WWW request with the given URL.
用给定的URL创建一个WWW请求。

Functions 函数

GetAudioClip Returns an AudioClip generated from the downloaded data (Read Only).
从下载数据,返回一个AudioClip(只读)。
LoadImageIntoTexture Replaces the contents of an existing Texture2D with an image from the downloaded data.
利用一个从下载数据中的图像来替换现有Texture2D。
LoadUnityWeb Loads the new web player data file.
加载新的web播放器数据文件。

Static Functions 静态函数

EscapeURL Escapes characters in a string to ensure they are URL-friendly.
转义字符串中的字符。
LoadFromCacheOrDownload Loads an AssetBundle with the specified version number from the cache. If the AssetBundle is not currently cached, it will automatically be downloaded and stored in the cache for future retrieval from local storage.
从缓存加载带有指定版本号的AssetBundle。如果AssetBundle不在当前缓存,它将自动下载并储存在缓存,以便以后从本地存储检索。
UnEscapeURL Converts URL-friendly escape sequences back to normal text.
将URL的转义字符恢复正常的文本。
script/unityengine/classes/www/www.txt · 最后更改: 2016/08/02 05:29 (外部编辑)