Advertisement
vitelize

Unity Build Scene bundle

Jul 30th, 2012
1,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. //From http://blogs.floriancavallo.fr/post/2012/07/28/Unity-Ajout-dynamique-delements-Partie-I-Asset-Bundle.aspx
  2. [@MenuItem("Assets/Build AssetBundles From Scene")]
  3.     static void BuildAssetBundle()
  4.     {
  5.         string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
  6.        
  7.         //make sure user has a scene selected:
  8.         if (Selection.objects.Length != 1 || !assetPath.Contains(".unity"))
  9.         {
  10.             EditorUtility.DisplayDialog("Scene Asset Bundle Creation", "Please select a single scene in your project.", "OK");
  11.             return;
  12.         }
  13.  
  14.         //set a save location for the bundle:
  15.         string savePath = EditorUtility.SaveFilePanel("Save Scene Asset Bundle", "", "", "unity3d");
  16.         if (savePath == "")
  17.         {
  18.             return;
  19.         }
  20.  
  21.         //save asset bundles for iphone and android:
  22.         string[] pathPieces = savePath.Split('.');
  23.  
  24.         BuildPipeline.BuildStreamedSceneAssetBundle(new string[] { assetPath }, pathPieces[0] + "." +pathPieces[1], BuildTarget.WebPlayer);
  25.        
  26.         //complete:
  27.         EditorApplication.Beep();
  28.         EditorUtility.DisplayDialog("Scene Asset Bundle Creation", "Done!", "OK");
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement