/// <summary> /// 重命名AB包 /// </summary> public void RenameBundle(string name) { for (int i = 0; i < _filePaths.Count; i++) { AssetFileInfo file = AssetBundleEditorUtility.GetFileInfoByPath(_filePaths[i]); file.ReadDependenciesFile(); file.Bundled = name; AssetImporter import = AssetImporter.GetAtPath(_filePaths[i]); import.assetBundleName = name; for (int j = 0; j < file.Dependencies.Count; j++) { AssetFileInfo depenFile = AssetBundleEditorUtility.GetFileInfoByPath(file.Dependencies[j]); if (depenFile.IndirectBundled.ContainsKey(Name)) { int number = depenFile.IndirectBundled[Name]; depenFile.IndirectBundled.Remove(Name); depenFile.IndirectBundled.Add(name, number); } if (depenFile.IndirectBundledRelation.ContainsKey(_filePaths[i])) { depenFile.IndirectBundledRelation[_filePaths[i]] = name; } } } AssetDatabase.RemoveAssetBundleName(Name, true); Name = name; }
private void Init() { _assetRootFolder = AssetBundleEditorUtility.GetFolderInfoByFullPath(Application.dataPath); AssetBundleEditorUtility.ReadAssetBundleConfig(); _buildPath = EditorPrefs.GetString(EditorPrefsTable.AssetBundleEditor_BuildPath, Application.streamingAssetsPath); _buildTarget = (BuildTarget)EditorPrefs.GetInt(EditorPrefsTable.AssetBundleEditor_BuildTarget, 5); _variant = EditorPrefs.GetString(EditorPrefsTable.AssetBundleEditor_Variant, ""); _box = new GUIStyle("Box"); _helpBox = new GUIStyle("HelpBox"); _preButton = new GUIStyle("PreButton"); _preDropDown = new GUIStyle("PreDropDown"); _LRSelect = new GUIStyle("LODSliderRangeSelected"); _prefabLabel = new GUIStyle("PR PrefabLabel"); _label = new GUIStyle("PR Label"); _brokenPrefabLabel = new GUIStyle("PR BrokenPrefabLabel"); _miniButtonLeft = new GUIStyle("MiniButtonLeft"); _miniButtonRight = new GUIStyle("MiniButtonRight"); _oLMinus = new GUIStyle("OL Minus"); _assetLabel = new GUIStyle("AssetLabel"); _redundant = EditorGUIUtility.IconContent("lightMeter/redLight"); _redundant.text = "Redundant"; }
/// <summary> /// 读取依赖的资源文件 /// </summary> public void ReadDependenciesFile() { if (!_isReadDependenciesFile) { _isReadDependenciesFile = true; AssetBundleEditorUtility.ReadAssetDependencies(AssetPath); } }
/// <summary> /// 读取子级资源 /// </summary> public void ReadChildAsset() { if (!_isReadChildAsset) { _isReadChildAsset = true; AssetBundleEditorUtility.ReadAssetsInChildren(this); } }
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 != null) { GUI.Button(new Rect(0, 0, 160, 20), _currentAB.Name, _preButton); if (GUI.Button(new Rect(160, 0, 80, 20), _currentAB.MemorySizeFormat, _preDropDown)) { _currentAB.ChangeSortMode(); } _currentABViewHeight += 20; for (int i = 0; i < _currentAB.Count; i++) { AssetFileInfo file = AssetBundleEditorUtility.GetFileInfoByPath(_currentAB[i]); if (_currentABFile == file) { GUI.Box(new Rect(0, _currentABViewHeight, 240, 15), "", _LRSelect); } GUIContent content = EditorGUIUtility.ObjectContent(null, file.AssetType); content.text = file.Name; if (GUI.Button(new Rect(5, _currentABViewHeight, 150, 15), content, _prefabLabel)) { _currentABFile = file; Selection.activeObject = _currentABFile.AssetObject; EditorGUIUtility.PingObject(_currentABFile.AssetObject); } GUI.Label(new Rect(160, _currentABViewHeight, 60, 15), file.MemorySizeFormat, _assetLabel); if (GUI.Button(new Rect(220, _currentABViewHeight, 20, 15), "", _oLMinus)) { _currentAB.RemoveAsset(_currentAB[i]); _currentABFile = null; } _currentABViewHeight += 20; } } _currentABViewHeight += 5; if (_currentABViewHeight < _currentABViewRect.height) { _currentABViewHeight = (int)_currentABViewRect.height; } GUI.EndGroup(); GUI.EndScrollView(); }
public AssetFileInfo(string fullPath, string name, string extension) : base(fullPath, name) { AssetType = AssetDatabase.GetMainAssetTypeAtPath(AssetPath); AssetObject = AssetDatabase.LoadAssetAtPath(AssetPath, AssetType); MemorySize = new FileInfo(FullPath).Length; MemorySizeFormat = EditorUtility.FormatBytes(MemorySize); Bundled = ""; IndirectBundled = new Dictionary <string, int>(); IndirectBundledRelation = new Dictionary <string, string>(); Dependencies = new List <string>(); IsValid = AssetBundleEditorUtility.IsValidFile(extension); IsRedundant = false; Extension = extension; }
/// <summary> /// 改变排序方式 /// </summary> public void ChangeSortMode() { if (_sortMode == BundleAssetSortMode.FromBig) { _sortMode = BundleAssetSortMode.FromSmall; _filePaths.Sort((a, b) => { AssetFileInfo afile = AssetBundleEditorUtility.GetFileInfoByPath(a); AssetFileInfo bfile = AssetBundleEditorUtility.GetFileInfoByPath(b); if (afile.MemorySize > bfile.MemorySize) { return(1); } else if (afile.MemorySize == bfile.MemorySize) { return(0); } else { return(-1); } }); } else { _sortMode = BundleAssetSortMode.FromBig; _filePaths.Sort((a, b) => { AssetFileInfo afile = AssetBundleEditorUtility.GetFileInfoByPath(a); AssetFileInfo bfile = AssetBundleEditorUtility.GetFileInfoByPath(b); if (afile.MemorySize > bfile.MemorySize) { return(-1); } else if (afile.MemorySize == bfile.MemorySize) { return(0); } else { return(1); } }); } }
/// <summary> /// 添加资源到AB包中 /// </summary> public void AddAsset(string filePath) { AssetFileInfo file = AssetBundleEditorUtility.GetFileInfoByPath(filePath); if (file.Bundled != Name) { file.Bundled = Name; MemorySize += file.MemorySize; file.ReadDependenciesFile(); file.UpdateRedundantState(); _filePaths.Add(filePath); for (int i = 0; i < file.Dependencies.Count; i++) { AssetFileInfo depenFile = AssetBundleEditorUtility.GetFileInfoByPath(file.Dependencies[i]); if (depenFile.IsValid) { if (!depenFile.IndirectBundled.ContainsKey(Name)) { depenFile.IndirectBundled.Add(Name, 0); MemorySize += depenFile.MemorySize; } depenFile.IndirectBundled[Name] = depenFile.IndirectBundled[Name] + 1; if (!depenFile.IndirectBundledRelation.ContainsKey(filePath)) { depenFile.IndirectBundledRelation.Add(filePath, Name); } depenFile.UpdateRedundantState(); } } MemorySizeFormat = EditorUtility.FormatBytes(MemorySize); } AssetImporter import = AssetImporter.GetAtPath(filePath); import.assetBundleName = Name; }
/// <summary> /// 从AB包中移除资源 /// </summary> public void RemoveAsset(string filePath) { AssetFileInfo file = AssetBundleEditorUtility.GetFileInfoByPath(filePath); if (file.Bundled == Name) { file.Bundled = ""; MemorySize -= file.MemorySize; file.ReadDependenciesFile(); file.UpdateRedundantState(); _filePaths.Remove(filePath); for (int i = 0; i < file.Dependencies.Count; i++) { AssetFileInfo depenFile = AssetBundleEditorUtility.GetFileInfoByPath(file.Dependencies[i]); if (depenFile.IndirectBundled.ContainsKey(Name)) { depenFile.IndirectBundled[Name] = depenFile.IndirectBundled[Name] - 1; if (depenFile.IndirectBundled[Name] <= 0) { depenFile.IndirectBundled.Remove(Name); MemorySize -= depenFile.MemorySize; } } if (depenFile.IndirectBundledRelation.ContainsKey(filePath)) { depenFile.IndirectBundledRelation.Remove(filePath); } depenFile.UpdateRedundantState(); } MemorySizeFormat = EditorUtility.FormatBytes(MemorySize); } AssetImporter import = AssetImporter.GetAtPath(filePath); import.assetBundleName = ""; }
private void AssetPropertyGUI() { if (_currentFile != null) { _currentFile.ReadDependenciesFile(); GUI.color = (_currentFile.IsRedundant ? Color.red : Color.white); _assetPropertyViewRect = new Rect((int)position.width - 420, 50, 400, 400); _assetPropertyScrollRect = new Rect((int)position.width - 420, 50, 400, _assetPropertyViewHeight); _assetPropertyScroll = GUI.BeginScrollView(_assetPropertyViewRect, _assetPropertyScroll, _assetPropertyScrollRect); GUI.BeginGroup(_assetPropertyScrollRect, _helpBox); _assetPropertyViewHeight = 5; GUIContent content = EditorGUIUtility.ObjectContent(null, _currentFile.AssetType); content.text = _currentFile.Name; GUI.Label(new Rect(5, _assetPropertyViewHeight, 40, 15), "Asset:"); if (GUI.Button(new Rect(50, _assetPropertyViewHeight, 280, 15), content, _prefabLabel)) { Selection.activeObject = _currentFile.AssetObject; EditorGUIUtility.PingObject(_currentFile.AssetObject); } GUI.enabled = (_currentAB != null && _currentFile.Bundled == ""); if (GUI.Button(new Rect(340, _assetPropertyViewHeight, 50, 15), "Bundle", _preButton)) { _currentAB.AddAsset(_currentFile.AssetPath); _currentFile = null; return; } GUI.enabled = true; _assetPropertyViewHeight += 20; GUI.Label(new Rect(5, _assetPropertyViewHeight, 330, 15), "Path: " + _currentFile.AssetPath); if (GUI.Button(new Rect(340, _assetPropertyViewHeight, 50, 15), "Copy", _preButton)) { GUIUtility.systemCopyBuffer = _currentFile.AssetPath; } _assetPropertyViewHeight += 20; if (_currentFile.Dependencies.Count > 0) { _isShowDependencies = EditorGUI.Foldout(new Rect(5, _assetPropertyViewHeight, 390, 15), _isShowDependencies, "Dependencies:", true); _assetPropertyViewHeight += 20; if (_isShowDependencies) { for (int i = 0; i < _currentFile.Dependencies.Count; i++) { AssetFileInfo file = AssetBundleEditorUtility.GetFileInfoByPath(_currentFile.Dependencies[i]); content = EditorGUIUtility.ObjectContent(null, file.AssetType); content.text = file.Name; if (GUI.Button(new Rect(45, _assetPropertyViewHeight, 350, 15), content, _prefabLabel)) { Selection.activeObject = file.AssetObject; EditorGUIUtility.PingObject(file.AssetObject); } _assetPropertyViewHeight += 20; } } } if (_currentFile.IndirectBundledRelation.Count > 0) { _isShowIndirectBundled = EditorGUI.Foldout(new Rect(5, _assetPropertyViewHeight, 390, 15), _isShowIndirectBundled, "Indirect Bundled:", true); _assetPropertyViewHeight += 20; if (_isShowIndirectBundled) { foreach (KeyValuePair <string, string> bundle in _currentFile.IndirectBundledRelation) { AssetFileInfo file = AssetBundleEditorUtility.GetFileInfoByPath(bundle.Key); content = EditorGUIUtility.ObjectContent(null, file.AssetType); content.text = file.Name + " >> " + bundle.Value; if (GUI.Button(new Rect(45, _assetPropertyViewHeight, 350, 15), content, _prefabLabel)) { Selection.activeObject = file.AssetObject; EditorGUIUtility.PingObject(file.AssetObject); } _assetPropertyViewHeight += 20; } } } _assetPropertyViewHeight += 5; if (_assetPropertyViewHeight < _assetPropertyViewRect.height) { _assetPropertyViewHeight = (int)_assetPropertyViewRect.height; } GUI.EndGroup(); GUI.EndScrollView(); GUI.color = Color.white; } }
private void AssetBundlesGUI() { _ABViewRect = new Rect(5, 45, 240, (int)position.height / 2 - 40); _ABScrollRect = new Rect(5, 45, 240, _ABViewHeight); _ABScroll = GUI.BeginScrollView(_ABViewRect, _ABScroll, _ABScrollRect); GUI.BeginGroup(_ABScrollRect, _box); _ABViewHeight = 5; for (int i = 0; i < AssetBundleEditorUtility.BundleInfosList.Count; i++) { BundleInfo bundle = AssetBundleEditorUtility.BundleInfosList[i]; string icon = bundle.Count > 0 ? "Prefab Icon" : "GameObject Icon"; if (_currentAB == bundle) { GUI.Box(new Rect(0, _ABViewHeight, 240, 15), "", _LRSelect); if (_isRename) { GUIContent content = EditorGUIUtility.IconContent(icon); content.text = ""; GUI.Label(new Rect(5, _ABViewHeight, 230, 15), content, _prefabLabel); _renameValue = EditorGUI.TextField(new Rect(40, _ABViewHeight, 140, 15), _renameValue); if (GUI.Button(new Rect(180, _ABViewHeight, 30, 15), "OK", _miniButtonLeft)) { if (_renameValue != "") { if (!AssetBundleEditorUtility.IsExistBundleInfo(_renameValue)) { AssetBundleEditorUtility.RenameBundleInfo(_currentAB.Name, _renameValue); _renameValue = ""; _isRename = false; } else { GlobalTools.LogError("Already existed AssetBundle name:" + _renameValue); } } } if (GUI.Button(new Rect(210, _ABViewHeight, 30, 15), "NO", _miniButtonRight)) { _isRename = false; } } else { GUIContent content = EditorGUIUtility.IconContent(icon); content.text = bundle.Name; GUI.Label(new Rect(5, _ABViewHeight, 230, 15), content, _prefabLabel); } } else { GUIContent content = EditorGUIUtility.IconContent(icon); content.text = bundle.Name; if (GUI.Button(new Rect(5, _ABViewHeight, 230, 15), content, _prefabLabel)) { _currentAB = bundle; _currentABFile = null; _isRename = false; } } _ABViewHeight += 20; } _ABViewHeight += 5; if (_ABViewHeight < _ABViewRect.height) { _ABViewHeight = (int)_ABViewRect.height; } GUI.EndGroup(); GUI.EndScrollView(); }
private void TitleGUI() { if (GUI.Button(new Rect(5, 5, 60, 15), "Create", _preButton)) { AssetBundleEditorUtility.GetBundleInfoByName("ab" + System.DateTime.Now.ToString("yyyyMMddHHmmssfff")); } GUI.enabled = (_currentAB != null); 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 " + _currentAB + " ?", "Yes", "No")) { _currentAB.ClearAsset(); } } if (GUI.Button(new Rect(185, 5, 60, 15), "Delete", _preButton)) { if (EditorUtility.DisplayDialog("Prompt", "Delete " + _currentAB + "?this will clear all assets!and this operation cannot be restore!", "Yes", "No")) { AssetBundleEditorUtility.DeleteBundleInfoByName(_currentAB.Name); _currentAB = null; } } GUI.enabled = true; _hideInvalidAsset = GUI.Toggle(new Rect(265, 5, 100, 15), _hideInvalidAsset, "Hide Invalid"); _hideBundleAsset = GUI.Toggle(new Rect(365, 5, 100, 15), _hideBundleAsset, "Hide Bundled"); _showOnlyRedundant = GUI.Toggle(new Rect(465, 5, 200, 15), _showOnlyRedundant, "Show Only Redundant"); GUI.Label(new Rect(5, 25, 60, 15), "Variant:"); _variant = EditorGUI.TextField(new Rect(70, 25, 110, 15), _variant); if (GUI.Button(new Rect(185, 25, 60, 15), "Apply", _preButton)) { EditorPrefs.SetString(EditorPrefsTable.AssetBundleEditor_Variant, _variant); } if (GUI.Button(new Rect(250, 25, 60, 15), "Open", _preButton)) { AssetBundleEditorUtility.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; EditorPrefs.SetString(EditorPrefsTable.AssetBundleEditor_BuildPath, _buildPath); } } GUI.Label(new Rect(370, 25, 70, 15), "Build Path:"); GUI.TextField(new Rect(440, 25, 300, 15), _buildPath); BuildTarget buildTarget = (BuildTarget)EditorGUI.EnumPopup(new Rect((int)position.width - 205, 5, 150, 15), _buildTarget, _preDropDown); if (buildTarget != _buildTarget) { _buildTarget = buildTarget; EditorPrefs.SetInt(EditorPrefsTable.AssetBundleEditor_BuildTarget, (int)_buildTarget); } if (GUI.Button(new Rect((int)position.width - 55, 5, 50, 15), "Build", _preButton)) { AssetBundleEditorUtility.BuildAssetBundles(); } }
private void OnDestroy() { AssetBundleEditorUtility.ClearData(); EditorUtility.UnloadUnusedAssetsImmediate(); System.GC.Collect(); }