原地址:http://www.linuxidc.com/Linux/2011-10/45888.htm
Download.cs
using UnityEngine;
using System.Collections;
using System.IO;
public class Download : MonoBehaviour
{
public string url = "http://ww3.sinaimg.cn/large/80dfe250jw1dle1r2v4t9j.jpg";
public GUIText Test;
WWW www;
Color Alpha;
bool Appear = false;
int a = 0;
IEnumerator Start()
{
www = new WWW(url);
//定义www为WWW类型并且等于所下载下来的WWW中内容。
yield return www;
//返回所下载的www的值
renderer.material.shader = Shader.Find("Transparent/Diffuse");
renderer.material.mainTexture = www.texture;
Texture2D newTexture = www.texture;
byte[] pngData = newTexture.EncodeToPNG();
try
{
if (Application.platform == RuntimePlatform.Android)
{
File.WriteAllBytes(Application.persistentDataPath + "/ICO.png", pngData);
}
else
{
File.WriteAllBytes(Application.dataPath + "/download/ICO.png", pngData);
}
}
catch(IOException e)
{
print(e);
}
Alpha = renderer.material.color;
Alpha.a = 0;
Appear = true;
renderer.enabled = true;
renderer.material.color = Alpha;
//将下载下来的WWW中的图片赋予到默认物体的材质上进行渲染出来
}
void Update()
{
Test.text = "DownLoad: " + www.progress;
if(www.progress == 1 && Appear)
{
a++;
Alpha = renderer.material.color;
Alpha.a += 0.01F;
renderer.material.color = Alpha;
}
if(Input.GetKey(KeyCode.Escape))
{
Application.Quit();
}
}
}
下载效果图:
![](https://i-blog.csdnimg.cn/blog_migrate/912f3f8c67fa8e54be3245ae5209a28c.gif)
由于上面的服务器测试用C#,所以这个羽化也改写成了C#,方便管理,这里需要注意的是,保存的图片是以我们规定的形式输出出去的,羽化把这图片做成了这个模型的贴图,渐变显示出来,这个模型有动作的,羽化也让它播放了出来,图片为网上任意找的一张图片,当然也是羽化喜欢的东西-0- 那可怜的工资带不动的爱啊- -
最后送上一张我们做的测试截图,Unity自带的Shader和高光贴图,虽然没有法线,效果还不错,消耗不是很大,还有很大上升空间~ ~ 手机上效果略次,微弱显示高光效果,有待改善- -