public AH_TreeviewElement(string absPath, int depth, int id, string relativepath, string assetID, List <string> scenesReferencing, bool isUsedInBuild) : base(System.IO.Path.GetFileName(absPath), depth, id) { this.absPath = absPath; this.relativePath = relativepath; this.guid = UnityEditor.AssetDatabase.AssetPathToGUID(relativepath); this.scenesReferencingAsset = scenesReferencing; this.usedInBuild = isUsedInBuild; //Return if its a folder if (isFolder = UnityEditor.AssetDatabase.IsValidFolder(relativepath)) { return; } //Return if its not an asset if (!string.IsNullOrEmpty(this.guid)) { this.assetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(relativepath); updateIconDictEntry(); if (isUsedInBuild) { UnityEngine.Object asset = UnityEditor.AssetDatabase.LoadMainAssetAtPath(relativepath); //#if UNITY_2017_1_OR_NEWER if (asset != null) { this.assetSize = Profiler.GetRuntimeMemorySizeLong(asset) / 2; } long max = UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong(); long used = UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong(); float percentUsed = ((float)(used) / (float)max) * 100f; //If 90% of avaliable memory spend, do a GC.Collect if (percentUsed > 90) { Debug.LogWarning("AH: Running out of memory, triggering GC.Collect"); UnityEditor.AssetDatabase.Refresh(); GC.Collect(); } } fileSize = new System.IO.FileInfo(absPath).Length; fileSizeStringRepresentation = AH_Utils.GetSizeAsString(fileSize); assestSizeStringRepresentation = AH_Utils.GetSizeAsString(assetSize); } }
public AH_TreeviewElement(string absPath, int depth, int id, string relativepath, string assetID, List <string> scenesReferencing, bool isUsedInBuild) : base(System.IO.Path.GetFileName(absPath), depth, id) { this.absPath = absPath; this.relativePath = relativepath; this.guid = UnityEditor.AssetDatabase.AssetPathToGUID(relativepath); this.scenesReferencingAsset = scenesReferencing; this.usedInBuild = isUsedInBuild; //Return if its a folder if (isFolder = UnityEditor.AssetDatabase.IsValidFolder(relativepath)) { return; } //Return if its not an asset if (!string.IsNullOrEmpty(this.guid)) { this.assetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(relativepath); updateIconDictEntry(); if (isUsedInBuild) { UnityEngine.Object asset = UnityEditor.AssetDatabase.LoadMainAssetAtPath(relativepath); //#if UNITY_2017_1_OR_NEWER if (asset != null) { this.assetSize = Profiler.GetRuntimeMemorySizeLong(asset) / 2; } } fileSize = new System.IO.FileInfo(absPath).Length; fileSizeStringRepresentation = AH_Utils.GetSizeAsString(fileSize); assestSizeStringRepresentation = AH_Utils.GetSizeAsString(assetSize); } }
private bool AddFilesRecursively(string absPath, AH_SerializedBuildInfo chosenBuildInfo, int treeViewDepth, ref int treeViewID, ref int folderCount, ref int foldersProcessed) { string relativePath; string folderID; AH_Utils.GetRelativePathAndAssetID(absPath, out relativePath, out folderID); //Check if this folder has been Ignored if (AH_SettingsManager.Instance.HasIgnoredFolder(relativePath, folderID)) { return(false); } //Add folder System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(absPath); string dirInfoName = dirInfo.Name; //Increment folder process count foldersProcessed++; EditorUtility.DisplayProgressBar("Analyzing project", relativePath, ((float)foldersProcessed / (float)folderCount)); //Todo make cancellable //Increment ID treeViewID++; AH_TreeviewElement threeViewFolder = new AH_TreeviewElement(dirInfoName, treeViewDepth, treeViewID, ((treeViewDepth != -1) ? relativePath : ""), "", null, false); treeElements.Add(threeViewFolder); //Increment depth treeViewDepth++; //Track if this folder has valid children bool hasValidChildren = false; foreach (var assetPath in System.IO.Directory.GetFiles(absPath).Where(val => Path.GetExtension(val) != ".meta"))// !val.EndsWith(".meta"))) { string relativepath; string assetID; AH_Utils.GetRelativePathAndAssetID(assetPath, out relativepath, out assetID); //If this is not an unity asset if (string.IsNullOrEmpty(assetID)) { continue; } //Has this file been Ignored? if (AH_SettingsManager.Instance.HasIgnoredAsset(relativepath, assetID)) { continue; } AH_SerializableAssetInfo usedAssetInfo = chosenBuildInfo.GetItemInfo(assetID); bool isAssetUsed = (usedAssetInfo != null); //TODO CONTINUE LOOP AND ADDING OF ASSETS treeViewID++; AH_TreeviewElement treeViewElement = new AH_TreeviewElement(assetPath, treeViewDepth, treeViewID, relativepath, assetID, ((isAssetUsed) ? usedAssetInfo.Refs : null), isAssetUsed); treeElements.Add(treeViewElement); hasValidChildren = true; } foreach (var dir in System.IO.Directory.GetDirectories(absPath)) { if (AddFilesRecursively(dir, chosenBuildInfo, treeViewDepth, ref treeViewID, ref folderCount, ref foldersProcessed)) { hasValidChildren = true; } } if (!hasValidChildren && (treeViewDepth != -1)) { treeElements.Remove(threeViewFolder); //Decrement ID treeViewID--; //Decrement depth treeViewDepth--; } //Return true if folder added succesfully return(hasValidChildren); }
void CellGUI(Rect cellRect, TreeViewItem <AH_TreeviewElement> item, MyColumns column, ref RowGUIArgs args) { // Center cell rect vertically (makes it easier to place controls, icons etc in the cells) CenterRectUsingSingleLineHeight(ref cellRect); AH_TreeviewElement element = (AH_TreeviewElement)item.data; switch (column) { case MyColumns.Icon: { if (item.data.AssetType != null) { GUI.DrawTexture(cellRect, AH_TreeviewElement.GetIcon(item.data.AssetType), ScaleMode.ScaleToFit); } } break; case MyColumns.Name: { Rect nameRect = cellRect; nameRect.x += GetContentIndent(item); DefaultGUI.Label(nameRect, item.data.m_Name, args.selected, args.focused); } break; case MyColumns.AssetSize: case MyColumns.FileSize: { string value = ""; if (column == MyColumns.AssetSize && element.AssetSize > 0) { value = element.AssetSizeStringRepresentation; } if (column == MyColumns.FileSize && element.FileSize > 0) { value = element.FileSizeStringRepresentation; } if (element.IsFolder && column == MyColumns.FileSize /*&& !IsExpanded(element.id)*/) { value = "{" + AH_Utils.BytesToString(element.GetFileSizeRecursively(((AH_MultiColumnHeader)multiColumnHeader).ShowMode)) + "}"; DefaultGUI.Label(cellRect, value, args.selected, args.focused); } else { DefaultGUI.LabelRightAligned(cellRect, value, args.selected, args.focused); } } break; case MyColumns.UsedInBuild: { if (item.data.UsedInBuild) { DefaultGUI.LabelRightAligned(cellRect, "\u2713", args.selected, args.focused); } } break; case MyColumns.LevelUsage: { if (item.data.UsedInBuild && item.data.ScenesReferencingAsset != null) { if (item.data.ScenesReferencingAsset.Count > 0) { string cellString = String.Format("Usage: {0}", item.data.ScenesReferencingAsset.Count.ToString()); if (args.selected && args.focused) { if (GUI.Button(cellRect, cellString)) { UnityEngine.Object[] sceneAssets = new UnityEngine.Object[item.data.ScenesReferencingAsset.Count]; string message = ""; for (int i = 0; i < item.data.ScenesReferencingAsset.Count; i++) { message += (item.data.ScenesReferencingAsset[i] + Environment.NewLine); sceneAssets[i] = AssetDatabase.LoadMainAssetAtPath(item.data.ScenesReferencingAsset[i]); } Selection.objects = sceneAssets; EditorUtility.DisplayDialog("Scenes referencing " + item.data.m_Name, message, "OK"); } } else { DefaultGUI.LabelRightAligned(cellRect, cellString, args.selected, args.focused); } } /*else * DefaultGUI.LabelRightAligned(cellRect, "Global", args.selected, args.focused);*/ } } break; } }