thieumao

LoadGameObject.cs - Load game object từ assetbunle Unity 4

Aug 20th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class LoadGameObject : MonoBehaviour {
  5.     public int version;
  6.     AssetBundle bundle;
  7.     public string url = "http://app.baib52.com/test/Cubes.unity3d";
  8.     public string url_android = "http://app.baib52.com/test/Cubes.unity3d.android.unity3d";
  9.     WWW www;
  10.     // Use this for initialization
  11.     void Start () {
  12.         StartCoroutine(LoadData());
  13.     }
  14.    
  15.     // Update is called once per frame
  16.     void Update () {
  17.    
  18.     }
  19.     IEnumerator LoadData()
  20.     {
  21.  
  22.         www = WWW.LoadFromCacheOrDownload(url, version);
  23.         //  www = new WWW(url);
  24.         yield return www;
  25.         Debug.Log(string.Format("Progress - {0}%. from {1}", www.progress * 100, www.url));
  26.         if (Application.platform == RuntimePlatform.Android)
  27.         {
  28.             www = WWW.LoadFromCacheOrDownload(url_android, version);
  29.             //  www = new WWW(url_android);
  30.             yield return www;
  31.  
  32.         }
  33.         //while (www.progress < 1)
  34.         //{
  35.         //    m_CurrentValue = www.progress * 100;
  36.         //    Debug.Log(string.Format("Progress - {0}%. from {1}", www.progress * 100, www.url));
  37.         //    yield return new WaitForSeconds(.1f);
  38.         //}
  39.         bundle = www.assetBundle;
  40.         GameObject obj = bundle.Load("Cubes", typeof(GameObject)) as GameObject;
  41.         Instantiate(obj);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment