/// <summary> /// 添加资源到AB包中 /// </summary> public static void AddAsset(this AssetBundleBuildInfo build, AssetInfo asset) { asset.Bundled = build.Name; asset.IsChecked = false; build.Assets.Add(asset); AssetImporter import = AssetImporter.GetAtPath(asset.AssetPath); import.assetBundleName = build.Name; }
/// <summary> /// 清空AB包中的资源 /// </summary> public static void ClearAsset(this AssetBundleBuildInfo build) { for (int i = 0; i < build.Assets.Count; i++) { build.Assets[i].Bundled = ""; AssetImporter import = AssetImporter.GetAtPath(build.Assets[i].AssetPath); import.assetBundleName = ""; } build.Assets.Clear(); }
/// <summary> /// 从AB包中删除资源 /// </summary> public static void RemoveAsset(this AssetBundleBuildInfo build, AssetInfo asset) { asset.Bundled = ""; if (build.Assets.Contains(asset)) { build.Assets.Remove(asset); } AssetImporter import = AssetImporter.GetAtPath(asset.AssetPath); import.assetBundleName = ""; }
/// <summary> /// 重命名AB包 /// </summary> public static void RenameAssetBundle(this AssetBundleBuildInfo build, string name) { List <string> bundles = AssetDatabase.GetAllAssetBundleNames().ToList(); if (bundles.Contains(build.Name)) { AssetDatabase.RemoveAssetBundleName(build.Name, true); } build.Name = name; for (int i = 0; i < build.Assets.Count; i++) { build.Assets[i].Bundled = build.Name; AssetImporter import = AssetImporter.GetAtPath(build.Assets[i].AssetPath); import.assetBundleName = build.Name; } }
/// <summary> /// 读取AB包配置信息 /// </summary> public static void ReadAssetBundleConfig(AssetBundleInfo abInfo, List <AssetInfo> validAssetList) { string[] builds = AssetDatabase.GetAllAssetBundleNames(); for (int i = 0; i < builds.Length; i++) { AssetBundleBuildInfo build = new AssetBundleBuildInfo(builds[i]); string[] assets = AssetDatabase.GetAssetPathsFromAssetBundle(builds[i]); for (int j = 0; j < assets.Length; j++) { AssetInfo ai = validAssetList.GetAssetInfoByGUID(AssetDatabase.AssetPathToGUID(assets[j])); if (ai != null) { build.AddAsset(ai); } } abInfo.AssetBundles.Add(build); } }
private void CurrentAssetBundlesGUI() { _currentABViewRect = new Rect(5, (int)position.height / 2 + 10, 240, (int)position.height / 2 - 15); _currentABScrollRect = new Rect(5, (int)position.height / 2 + 10, 240, _currentABViewHeight); _currentABScroll = GUI.BeginScrollView(_currentABViewRect, _currentABScroll, _currentABScrollRect); GUI.BeginGroup(_currentABScrollRect, _box); _currentABViewHeight = 5; if (_currentAB != -1) { AssetBundleBuildInfo build = _assetBundle.AssetBundles[_currentAB]; for (int i = 0; i < build.Assets.Count; i++) { if (_currentABAsset == i) { GUI.Box(new Rect(0, _currentABViewHeight, 240, 15), "", _LRSelect); } GUIContent content = EditorGUIUtility.ObjectContent(null, build.Assets[i].AssetType); content.text = build.Assets[i].AssetName; if (GUI.Button(new Rect(5, _currentABViewHeight, 205, 15), content, _prefabLabel)) { _currentABAsset = i; } if (GUI.Button(new Rect(215, _currentABViewHeight, 20, 15), "", _oLMinus)) { build.RemoveAsset(build.Assets[i]); _currentABAsset = -1; } _currentABViewHeight += 20; } } _currentABViewHeight += 5; if (_currentABViewHeight < _currentABViewRect.height) { _currentABViewHeight = (int)_currentABViewRect.height; } GUI.EndGroup(); GUI.EndScrollView(); }
private void TitleGUI() { if (GUI.Button(new Rect(5, 5, 60, 15), "Create", _preButton)) { AssetBundleBuildInfo build = new AssetBundleBuildInfo("ab" + System.DateTime.Now.ToString("yyyyMMddHHmmss")); _assetBundle.AssetBundles.Add(build); } GUI.enabled = _currentAB == -1 ? false : true; if (GUI.Button(new Rect(65, 5, 60, 15), "Rename", _preButton)) { _isRename = !_isRename; } if (GUI.Button(new Rect(125, 5, 60, 15), "Clear", _preButton)) { if (EditorUtility.DisplayDialog("Prompt", "Clear " + _assetBundle.AssetBundles[_currentAB].Name + " ?", "Yes", "No")) { _assetBundle.AssetBundles[_currentAB].ClearAsset(); } } if (GUI.Button(new Rect(185, 5, 60, 15), "Delete", _preButton)) { if (EditorUtility.DisplayDialog("Prompt", "Delete " + _assetBundle.AssetBundles[_currentAB].Name + "?This will clear all assets!", "Yes", "No")) { _assetBundle.DeleteAssetBundle(_currentAB); _currentAB = -1; } } if (GUI.Button(new Rect(250, 5, 100, 15), "Add Assets", _preButton)) { List <AssetInfo> assets = _validAssets.GetCheckedAssets(); for (int i = 0; i < assets.Count; i++) { _assetBundle.AssetBundles[_currentAB].AddAsset(assets[i]); } } GUI.enabled = true; if (GUI.Button(new Rect(250, 25, 60, 15), "Open", _preButton)) { AssetBundleTool.OpenFolder(_buildPath); } if (GUI.Button(new Rect(310, 25, 60, 15), "Browse", _preButton)) { string path = EditorUtility.OpenFolderPanel("Select Path", Application.dataPath, ""); if (path.Length != 0) { _buildPath = path; AssetBundleTool.EditorConfigInfo.BuildPath = _buildPath; AssetBundleTool.SaveEditorConfigInfo(); } } GUI.Label(new Rect(370, 25, 70, 15), "Build Path:"); _buildPath = GUI.TextField(new Rect(440, 25, 300, 15), _buildPath); if (GUI.Button(new Rect(250, 45, 100, 15), "Expand All", _preButton)) { AssetBundleTool.ExpandFolder(_asset, true); } if (GUI.Button(new Rect(350, 45, 100, 15), "Shrink All", _preButton)) { AssetBundleTool.ExpandFolder(_asset, false); } _hideInvalidAsset = GUI.Toggle(new Rect(460, 45, 100, 15), _hideInvalidAsset, "Hide Invalid"); _hideBundleAsset = GUI.Toggle(new Rect(560, 45, 100, 15), _hideBundleAsset, "Hide Bundled"); _showSetting = GUI.Toggle(new Rect((int)position.width - 135, 5, 80, 15), _showSetting, "Setting", _preButton); if (GUI.Button(new Rect((int)position.width - 55, 5, 50, 15), "Build", _preButton)) { AssetBundleTool.BuildAssetBundles(); } }