| | |
| | | using UnityEditor; |
| | | using System.IO; |
| | | |
| | | public class AssetBundleBuildExtersion |
| | | { |
| | | public static void Build(string _output, string _category, BuildAssetBundleOptions _bundleOption, BuildTarget _buildTarget) |
| | | { |
| | | var assetBundles = AssetDatabase.GetAllAssetBundleNames(); |
| | | |
| | | List<string> targetAssetBundles = new List<string>(); |
| | | for (int i = 0; i < assetBundles.Length; i++) |
| | | { |
| | | var bundleName = assetBundles[i]; |
| | | if (bundleName.StartsWith(_category)) |
| | | { |
| | | targetAssetBundles.Add(bundleName); |
| | | } |
| | | } |
| | | |
| | | var assets = new List<AssetBundleBuild>(); |
| | | |
| | | for (int i = 0; i < targetAssetBundles.Count; i++) |
| | | { |
| | | var assetBundleBuild = new AssetBundleBuild(); |
| | | assetBundleBuild.assetBundleName = targetAssetBundles[i]; |
| | | assetBundleBuild.assetNames = AssetDatabase.GetAssetPathsFromAssetBundle(targetAssetBundles[i]); |
| | | assets.Add(assetBundleBuild); |
| | | } |
| | | |
| | | var rootPath = StringUtility.Contact(Application.dataPath.Replace("Assets", ""), _output, Path.AltDirectorySeparatorChar, _category); |
| | | var mainFile = StringUtility.Contact(Application.dataPath.Replace("Assets", ""), _output, Path.AltDirectorySeparatorChar, GetMainFestFileName(_buildTarget)); |
| | | var mainFileRename = StringUtility.Contact(Application.dataPath.Replace("Assets", ""), _output, Path.AltDirectorySeparatorChar, _category, "_assetbundle"); |
| | | var manifest = StringUtility.Contact(Application.dataPath.Replace("Assets", ""), _output, Path.AltDirectorySeparatorChar, GetMainFestFileName(_buildTarget), ".manifest"); |
| | | var manifestRename = StringUtility.Contact(Application.dataPath.Replace("Assets", ""), _output, Path.AltDirectorySeparatorChar, _category, "_assetbundle.manifest"); |
| | | |
| | | if (Directory.Exists(rootPath)) |
| | | { |
| | | Directory.Delete(rootPath, true); |
| | | } |
| | | |
| | | Directory.CreateDirectory(rootPath); |
| | | |
| | | if (File.Exists(mainFileRename)) |
| | | { |
| | | File.Delete(mainFileRename); |
| | | } |
| | | |
| | | if (File.Exists(manifestRename)) |
| | | { |
| | | File.Delete(manifestRename); |
| | | } |
| | | |
| | | BuildPipeline.BuildAssetBundles(_output, assets.ToArray(), _bundleOption, _buildTarget); |
| | | |
| | | File.Move(mainFile, mainFileRename); |
| | | File.Move(manifest, manifestRename); |
| | | |
| | | } |
| | | |
| | | static string GetMainFestFileName(BuildTarget _target) |
| | | { |
| | | switch (_target) |
| | | { |
| | | case BuildTarget.StandaloneWindows: |
| | | return "standalone"; |
| | | case BuildTarget.Android: |
| | | return "android"; |
| | | case BuildTarget.iOS: |
| | | return "ios"; |
| | | default: |
| | | return string.Empty; |
| | | } |
| | | public class AssetBundleBuildExtersion
|
| | | {
|
| | | public static void Build(string _output, string _category, BuildAssetBundleOptions _bundleOption, BuildTarget _buildTarget)
|
| | | {
|
| | | var assetBundles = AssetDatabase.GetAllAssetBundleNames();
|
| | |
|
| | | List<string> targetAssetBundles = new List<string>();
|
| | | for (int i = 0; i < assetBundles.Length; i++)
|
| | | {
|
| | | var bundleName = assetBundles[i];
|
| | | if (bundleName.StartsWith(_category))
|
| | | {
|
| | | targetAssetBundles.Add(bundleName);
|
| | | }
|
| | | }
|
| | |
|
| | | var assets = new List<AssetBundleBuild>();
|
| | |
|
| | | for (int i = 0; i < targetAssetBundles.Count; i++)
|
| | | {
|
| | | var assetBundleBuild = new AssetBundleBuild();
|
| | | assetBundleBuild.assetBundleName = targetAssetBundles[i];
|
| | | assetBundleBuild.assetNames = AssetDatabase.GetAssetPathsFromAssetBundle(targetAssetBundles[i]);
|
| | | assets.Add(assetBundleBuild);
|
| | | }
|
| | |
|
| | | var rootPath = StringUtility.Contact(_output, Path.AltDirectorySeparatorChar, _category);
|
| | | var mainFile = StringUtility.Contact(_output, Path.AltDirectorySeparatorChar, GetMainFestFileName(_buildTarget));
|
| | | var mainFileRename = StringUtility.Contact(_output, Path.AltDirectorySeparatorChar, _category, "_assetbundle");
|
| | | var manifest = StringUtility.Contact(_output, Path.AltDirectorySeparatorChar, GetMainFestFileName(_buildTarget), ".manifest");
|
| | | var manifestRename = StringUtility.Contact(_output, Path.AltDirectorySeparatorChar, _category, "_assetbundle.manifest");
|
| | |
|
| | | if (Directory.Exists(rootPath))
|
| | | {
|
| | | Directory.Delete(rootPath, true);
|
| | | }
|
| | |
|
| | | Directory.CreateDirectory(rootPath);
|
| | |
|
| | | if (File.Exists(mainFileRename))
|
| | | {
|
| | | File.Delete(mainFileRename);
|
| | | }
|
| | |
|
| | | if (File.Exists(manifestRename))
|
| | | {
|
| | | File.Delete(manifestRename);
|
| | | }
|
| | |
|
| | | BuildPipeline.BuildAssetBundles(_output, assets.ToArray(), _bundleOption, _buildTarget);
|
| | |
|
| | | File.Move(mainFile, mainFileRename);
|
| | | File.Move(manifest, manifestRename);
|
| | |
|
| | | }
|
| | |
|
| | | static string GetMainFestFileName(BuildTarget _target)
|
| | | {
|
| | | switch (_target)
|
| | | {
|
| | | case BuildTarget.StandaloneWindows:
|
| | | return "standalone";
|
| | | case BuildTarget.Android:
|
| | | return "android";
|
| | | case BuildTarget.iOS:
|
| | | return "ios";
|
| | | default:
|
| | | return string.Empty;
|
| | | }
|
| | | } |
| | | |
| | | } |