Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System.Linq;
  2. using UnityEngine;
  3. using UnityEditor;
  4. using UnityEngine.SceneManagement;
  5. using System;
  6.  
  7. public class BundleCreatorCaller
  8. {
  9.     static BundleCrator instace = new BundleCrator();
  10.  
  11.     [MenuItem("Assets/Publish map to the bundle")]
  12.     static void Create() => instace.Execute();
  13.  
  14.     class BundleCrator
  15.     {
  16.         const string OutputFolder = "C:/vespiary/Lastest build/Bundles/locations20";
  17.  
  18.         public void Execute()
  19.         {
  20.             PrefabUtility.SaveAsPrefabAsset(rootObject, prefabPath);
  21.             AssetImporter.GetAtPath(prefabPath).SetAssetBundleNameAndVariant(bundleName, "");
  22.             BuildPipeline.BuildAssetBundles(OutputFolder, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
  23.             AssetDatabase.DeleteAsset(prefabPath);
  24.             AssetDatabase.RemoveUnusedAssetBundleNames();
  25.  
  26.             Debug.Log($"Bundle {bundleName} is done");
  27.         }
  28.  
  29.         Scene scene => SceneManager.GetActiveScene();
  30.        
  31.         GameObject rootObject => GameObject.Find("map");
  32.        
  33.         string bundleName => sceneFolder.ToLower();
  34.        
  35.         string prefabPath => "Assets/map.prefab";
  36.  
  37.         string sceneName => scene.path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();
  38.  
  39.         string sceneFolder => scene.path.Replace(sceneName,string.Empty).Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement