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 }

 

转载于:https://www.cnblogs.com/luxishi/p/6638617.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值