// private const char SEPERATOR = ','; // private static void SaveRepeatAssets(List<string> assets) // { // var sb = new StringBuilder(assets.Count * 10); // bool first = true; // foreach (var asset in assets) // { // if (!first) // { // sb.Append(SEPERATOR); // } // else // { // first = false; // } // // sb.Append(asset); // } // // var key = $"{UnityPathFileUtil.GetProjectName()}_TAB_REPEAT_ASSETS"; // EditorPrefs.SetString(key, sb.ToString()); // } // // private static void CheckAndClearOldRepeatAssets() // { // var key = $"{UnityPathFileUtil.GetProjectName()}_TAB_REPEAT_ASSETS"; // var value = EditorPrefs.GetString(key, String.Empty); // // if (String.IsNullOrEmpty(value)) return; // // var assets = value.Split(SEPERATOR); // foreach (var asset in assets) // { // var importer = AssetImporter.GetAtPath(asset); // if (importer != null) // { // importer.assetBundleName = String.Empty; // } // } // // EditorPrefs.SetString(key, String.Empty); // } private static void InternalBuildAssetBundle(AssetBundleConfig abConfig, AssetBundleBuild[] builds) { if (builds == null) { BuildPipeline.BuildAssetBundles(abConfig.outputPath, abConfig.buildAssetBundleOptions, EditorUserBuildSettings.activeBuildTarget); } else { BuildPipeline.BuildAssetBundles(abConfig.outputPath, builds, abConfig.buildAssetBundleOptions, EditorUserBuildSettings.activeBuildTarget); } AssetDatabase.Refresh(); }
public static void Build(AssetBundleConfig abConfig) { if (!Directory.Exists(abConfig.outputPath)) { Directory.CreateDirectory(abConfig.outputPath); } // CheckAndClearOldRepeatAssets(); ClearUselessAssetBundleFiles(abConfig.outputPath); var assets = new List <string>(); foreach (var abName in AssetDatabase.GetAllAssetBundleNames()) { foreach (var assetPath in AssetDatabase.GetAssetPathsFromAssetBundle(abName)) { assets.Add(assetPath); } } AddAssetBundleNameForRepeatDependencies(assets); InternalBuildAssetBundle(abConfig, null); }
void OnGUI() { if (ReferenceEquals(_abConfig, null)) { _abConfig = AssetBundleBuilder.GetOrCreateConfig(); } using (var cc = new EditorGUI.ChangeCheckScope()) { GUILayout.Label("Path"); GUILayout.BeginHorizontal(); GUILayout.Label(AssetBundleBuilder.ASSET_STREAMING_PATH, GUILayout.Width(145)); _abConfig.rootPath = GUILayout.TextField(_abConfig.rootPath); if (GUILayout.Button("Select", GUILayout.Width(45))) { string path = EditorUtility.OpenFolderPanel("Output path", _abConfig.outputPath, ""); if (!String.IsNullOrEmpty(path)) { if (path.Contains(AssetBundleBuilder.ASSET_STREAMING_PATH)) { _abConfig.rootPath = path.Replace(Application.dataPath, "Assets") .Replace(AssetBundleBuilder.ASSET_STREAMING_PATH, ""); } else { Debug.LogError("Invalid path, please select path in StreamingAssets."); } } } GUILayout.EndHorizontal(); GUILayout.Label("BuildAssetBundleOption:"); _abConfig.buildAssetBundleOptions = (BuildAssetBundleOptions)EditorGUILayout.EnumPopup(_abConfig.buildAssetBundleOptions); GUILayout.BeginHorizontal(); _abConfig.autoRebuildWhenBuildPlayer = GUILayout.Toggle(_abConfig.autoRebuildWhenBuildPlayer, "autoRebuildWhenBuildPlayer"); GUILayout.EndHorizontal(); if (cc.changed) { EditorUtility.SetDirty(_abConfig); AssetDatabase.SaveAssets(); } } bool empty = true; if (Directory.Exists(_abConfig.outputPath)) { empty = !Directory.EnumerateFileSystemEntries(_abConfig.outputPath).Any(); } EditorGUI.BeginDisabledGroup(empty); if (GUILayout.Button("Clear All")) { bool clearFolder = EditorUtility.DisplayDialog("Alert", $"Delete all file in folder:{UnityPathFileUtil.AssetPathToPath(_abConfig.outputPath)}?", "Yes", "No"); if (clearFolder) { UnityPathFileUtil.ClearFolder(_abConfig.outputPath); AssetDatabase.Refresh(); } } if (GUILayout.Button("Clear Useless")) { AssetBundleBuilder.ClearUselessAssetBundleFiles(_abConfig.outputPath); } EditorGUI.EndDisabledGroup(); if (GUILayout.Button("Build")) { AssetBundleBuilder.Build(_abConfig); } }
private void Initial() { _abConfig = AssetBundleBuilder.GetOrCreateConfig(); }