方法
using UnityEngine;
public class Api : MonoBehaviour
{
public string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
IEnumerator Start()
{
WWW www = new WWW(url);
yield return www;
Renderer renderer = GetComponent<Renderer>();
renderer.material.mainTexture = www.texture;
}
}
这种方法是在网络中下载图片,并赋予给物体材质,物体需要一个mesh rendeer
www不仅可以下载图片,还可以下载例如文本,音频
Variables变量
text
Returns the contents of the fetched web page as a string (Read Only).
通过网页获取并以字符串的形式返回内容(只读)。
bytes
Returns the contents of the fetched web page as a byte array (Read Only).
以字节组的形式返回获取到的网络页面中的内容(只读)。
error
Returns an error message if there was an error during the download (Read Only).
返回一个错误消息,在下载期间如果产生了一个错误的话。(只读)
texture
Returns a Texture2D generated from the downloaded data (Read Only).
从下载的数据返回生成的一个Texture2D(只读)。
audioClip
Returns a AudioClip generated from the downloaded data (Read Only).
从下载的数据,返回一个AudioClip。(只读)
movie
Returns a MovieTexture generated from the downloaded data (Read Only).
从下载的数据,返回一个MovieTexture(只读)。
isDone
Is the download already finished? (Read Only)
判断下载是否已经完成(只读)?
progress
How far has the download progressed (Read Only).
下载进度有多少(只读)?
uploadProgress
How far has the upload progressed (Read Only).
上传进度有多少(只读)
oggVorbis
Load an Ogg Vorbis file into the audio clip.
加载一个Ogg Vorbis文件到音频剪辑。
url
The URL of this WWW request (Read Only).
该WWW请求的URL(只读)。
assetBundle
Streams an AssetBundle that can contain any kind of asset from the project folder.
AssetBundle的数据流,可以包含项目文件夹中的任何类型资源。
threadPriority
Priority of AssetBundle decompression thread.
AssetBundle解压缩线程的优先级。
Constructors构造器
WWW
Creates a WWW request with the given URL.
用给定的URL创建一个WWW请求。
Functions函数
GetAudioClip
Returns a 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播放器数据文件。
Class Functions类函数
EscapeURL
Encodes string into an URL-friendly format.
字符串编码成一个URL的格式。
UnEscapeURL
Decodes string from an URL-friendly format.
从一个URL格式解码字符串。
LoadFromCacheOrDownload
Loads an assetBundle from the cache, or downloads it, in case it is not cached.
从缓存加载一个资源包,如果没有被缓存,或从下载加载。