动态加载资源的进度条实现

using UnityEngine;
using System.Collections;
using System;
public class DownScript : MonoBehaviour {

public GUIStyle progressbar_bj;   //背景图
public GUIStyle progressbar_qj;   //前景图
public GameObject obj;
WWW www;
bool loading=true;

public Texture img;

void Start () {
   StartCoroutine(ABC("http://images.earthcam.com/ec_metros/ourcams/fridays.jpg"));
}

// Update is called once per frame
void Update ()
{
}


void OnGUI ()
{
//~ GUI.Skin=big;
   if(loading)
   {

    GUI.Label(new Rect(100,30,200,30),"", progressbar_bj);
    GUI.Label(new Rect(100,30,www.progress*200,30),"", progressbar_qj);
    GUI.Label (new Rect (150,35, 200, 30),"Loading: "+  Convert.ToInt32(www.progress*100)+"%");
         print(www.progress);
           }
}

public IEnumerator ABC(string URL)
{
www = new WWW (URL);
yield return www;
if(!www.isDone)
   {
   loading=true;
   }
   else
   {
   loading=false;
   obj.renderer.material.mainTexture = www.texture;
   www=null;
   }
}

}

posted @ 2012-03-21 14:04  渡蓝  阅读(352)  评论(0)    收藏  举报