public static void ClearUselessAssetBundleFiles(string path) { AssetDatabase.RemoveUnusedAssetBundleNames(); bool IsAssetBundleFile(string s) { if (s.Contains('.')) { return(false); } var ab = AssetDatabase.LoadAssetAtPath <AssetBundle>(s); return(ab == null); } var list = AssetDatabase.GetAllAssetBundleNames().Select(x => path + "/" + x).ToList(); var abFiles = UnityPathFileUtil.GetAllFilesInProject(path); var assetBundleName = path + "/AssetBundle"; foreach (var v in abFiles) { if (v == assetBundleName) { continue; } if (!IsAssetBundleFile(v)) { continue; } if (!list.Contains(v)) { var _path = Application.dataPath.Replace("Assets", "") + v; if (File.Exists(_path)) { File.Delete(_path); } var _manifest = _path + ".manifest"; if (File.Exists(_manifest)) { File.Delete(_manifest); } } } AssetDatabase.Refresh(); }
private static void MarkAsPackage_Name() { var assets = Selection.GetFiltered <Object>(SelectionMode.DeepAssets); for (var i = 0; i < assets.Length; i++) { var asset = assets[i]; var path = AssetDatabase.GetAssetPath(asset); if (Directory.Exists(path)) { var name = asset.name; var assetsInFolder = UnityPathFileUtil.GetAllFiles(path); foreach (var v in assetsInFolder) { var importer = AssetImporter.GetAtPath(v); importer.assetBundleName = name; } } } }
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); } }