• 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 }
  • 相关阅读:
    iOS 微信支付SDK与微信友盟分享两者同时集成时,出现的问题与解决之路。
    Object-C语言Block的实现方式
    使用Mac命令别名,提升工作效率
    利用OC对象的消息重定向forwardingTargetForSelector方法构建高扩展性的滤镜功能
    渐变色进度条的两种绘制方案
    设计模式应用场景之Model设计中可以用到的设计模式
    有趣的赫夫曼树
    技术团队管理者的问题视角
    SSH安全登陆原理:密码登陆与公钥登陆
    为什么HashMap继承了AbstractMap还要实现Map?
  • 原文地址:https://www.cnblogs.com/luxishi/p/6638617.html
Copyright © 2020-2023  润新知