Advertisement
vitelize

Unity Load Scene bundle (LoadLevelAdditive)

Aug 9th, 2012
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. // From http://blogs.floriancavallo.fr/post/2012/07/28/Unity-Ajout-dynamique-delements-Partie-II-Telechargement-et-affichage.aspx
  2.  
  3. void Start()
  4.     {
  5.         string url = "http://server.com/scene.unity3d";
  6.         StartCoroutine(StartDownloadScene(url));
  7.     }
  8.  
  9. void OnGUI()
  10.     {
  11.         if (progress != 100)
  12.         {
  13.             GUILayout.Label(progress + "%");
  14.             GUI.BeginGroup(new Rect(pos.x, pos.y, progress, size.y));
  15.  
  16.             // Define progress bar texture within customStyle under Normal > Background
  17.             GUI.Box(new Rect(0, 0, size.x, size.y), "", customStyle);
  18.  
  19.             // Always match BeginGroup calls with an EndGroup call
  20.             GUI.EndGroup();
  21.     }
  22.  
  23.         }
  24.  
  25. IEnumerator StartDownloadScene(string url)
  26.     {
  27.         WWW download = new WWW(url);
  28.         while (!download.isDone)
  29.         {
  30.             //Ici on gère la barre de progression
  31.             progress = System.Convert.ToInt32(download.progress * 100);
  32.            
  33.             //On attend sagement la fin du téléchargement
  34.             yield return null;
  35.         }
  36.         //On charge la scène ainsi téléchargée.
  37.         Application.LoadLevelAdditive("Ma scene");      
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement