Unity導出AssetBundle到指定路徑


 1 using System.Collections;
 2 using UnityEngine;
 3 using UnityEditor;
 4 using System.IO;
 5 
 6 /// <summary>
 7 /// 把工程中設置了AssetBundle Name的資源打包成.unity3d 到StreamingAssets目錄下
 8 /// </summary>
 9 public class ExportAssetBundle : EditorWindow
10 {
11     // public static string sourcePath = Application.dataPath + "/Resources";
12     private string OutputPath = "Assets/StreamingAssets";
13 
14     [MenuItem("AssetsManager/導出所有AssetBundle")]
15     static void AddWindow()
16     {
17         //創建窗口
18         ExportAssetBundle window = (ExportAssetBundle)EditorWindow.GetWindowWithRect(typeof(ExportAssetBundle),new Rect(Screen.width/2,Screen.height/2,400,80), true, "導出AssetBundle");
19         window.Show();
20 
21     }
22 
23 
24     void OnGUI()
25     {
26         EditorGUILayout.BeginHorizontal();
27         GUILayout.Label("導出路徑:");
28         OutputPath = EditorGUILayout.TextField(OutputPath);
29         if (GUILayout.Button("瀏覽"))
30         {
31             //EditorApplication.delayCall += OpenFolder;
32             OutputPath = EditorUtility.OpenFolderPanel("選擇要導出的路徑", "", "");
33         }
34         EditorGUILayout.EndHorizontal();
35         if (GUILayout.Button("打包",GUILayout.MinHeight(50)))
36         {
37             BuildAssetBundle();
38             this.Close();
39         }
40     }
41 
42 
43     public void BuildAssetBundle()
44     {
45         string outputPath = Path.Combine(OutputPath, Platform.GetPlatformFolder(EditorUserBuildSettings.activeBuildTarget));
46         if (!Directory.Exists(outputPath))
47         {
48             Directory.CreateDirectory(outputPath);
49         }
50 
51         //根據BuildSetting里面所激活的平台進行打包
52         BuildPipeline.BuildAssetBundles(outputPath, 0, EditorUserBuildSettings.activeBuildTarget);
53 
54         AssetDatabase.Refresh();
55 
56         Debug.Log("打包完成");
57 
58     }
59 }
60 
61 public class Platform
62 {
63     public static string GetPlatformFolder(BuildTarget target)
64     {
65         switch (target)
66         {
67             case BuildTarget.Android:
68                 return "Android";
69             case BuildTarget.iOS:
70                 return "IOS";
71             case BuildTarget.WebGL:
72                 return "WebGL";
73             case BuildTarget.StandaloneWindows:
74             case BuildTarget.StandaloneWindows64:
75                 return "Windows";
76             case BuildTarget.StandaloneOSXIntel:
77             case BuildTarget.StandaloneOSXIntel64:
78             case BuildTarget.StandaloneOSXUniversal:
79                 return "OSX";
80             default:
81                 return null;
82         }
83     }
84 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM