Ejemplo n.º 1
0
        static int SortByAssetNameDescending(BuildReportTool.SizePart entry1, BuildReportTool.SizePart entry2)
        {
            int result = string.Compare(System.IO.Path.GetFileName(entry1.Name), System.IO.Path.GetFileName(entry2.Name),
                                        StringComparison.OrdinalIgnoreCase);

            return(result);
        }
Ejemplo n.º 2
0
        public static BuildReportTool.SizePart CreateSizePartFromFile(string filename, string fileFullPath)
        {
            BuildReportTool.SizePart outPart = new BuildReportTool.SizePart();

            outPart.Name = System.Security.SecurityElement.Escape(filename);

            if (File.Exists(fileFullPath))
            {
                long fileSizeBytes = GetFileSizeInBytes(fileFullPath);
                outPart.RawSizeBytes = fileSizeBytes;
                outPart.RawSize      = GetBytesReadable(fileSizeBytes);


                long importedSizeBytes = -1;
                //importedSizeBytes = BRT_LibCacheUtil.GetImportedFileSize(filename);

                outPart.ImportedSizeBytes = importedSizeBytes;
                outPart.ImportedSize      = BuildReportTool.Util.GetBytesReadable(importedSizeBytes);
            }
            else
            {
                outPart.RawSizeBytes = -1;
                outPart.RawSize      = "???";
            }

            /// \todo perhaps compute percentage: file size of this DLL out of total build size (would need to convert string of total build size into an int of bytes)
            outPart.Percentage = -1;

            return(outPart);
        }
Ejemplo n.º 3
0
 static void AddToSize(BuildReportTool.SizePart buildSize, long sizeToAdd)
 {
     if (buildSize != null)
     {
         buildSize.DerivedSize += sizeToAdd;
         buildSize.Size         = BuildReportTool.Util.GetBytesReadable(buildSize.DerivedSize);
     }
 }
 public void AddToSumSelection(BuildReportTool.SizePart b)
 {
     if (_selectedForSum.ContainsKey(b.Name))
     {
         // already added
         return;
     }
     _selectedForSum.Add(b.Name, b);
 }
Ejemplo n.º 5
0
        // Sum Selection: Commands
        // --------------------------------------------------------------------

        public void ToggleSumSelection(BuildReportTool.SizePart b)
        {
            if (InSumSelection(b))
            {
                RemoveFromSumSelection(b);
            }
            else
            {
                AddToSumSelection(b);
            }
        }
Ejemplo n.º 6
0
        void DrawAssetList(BuildReportTool.AssetList assetList)
        {
            BuildReportTool.SizePart[] assetsToShow = assetList.TopTenLargest;

            if (assetsToShow == null)
            {
                Debug.LogError("no top ten largest");
                return;
            }

            bool useAlt = true;

            GUILayout.BeginHorizontal();

            // 1st column: name
            GUILayout.BeginVertical();
            for (int n = 0; n < assetsToShow.Length; ++n)
            {
                BuildReportTool.SizePart b = assetsToShow[n];

                string styleToUse = useAlt ? BuildReportTool.Window.Settings.LIST_NORMAL_ALT_STYLE_NAME : BuildReportTool.Window.Settings.LIST_NORMAL_STYLE_NAME;

                string  prettyName = " " + (n + 1) + ". " + Path.GetFileName(b.Name);
                Texture icon       = AssetDatabase.GetCachedIcon(b.Name);
                if (GUILayout.Button(new GUIContent(prettyName, icon), styleToUse, GUILayout.MinWidth(100), GUILayout.MaxWidth(400), GUILayout.Height(30)))
                {
                    Utility.PingAssetInProject(b.Name);
                }

                useAlt = !useAlt;
            }
            GUILayout.EndVertical();

            // 2nd column: size
            useAlt = true;
            GUILayout.BeginVertical();
            for (int n = 0; n < assetsToShow.Length; ++n)
            {
                BuildReportTool.SizePart b = assetsToShow[n];

                string styleToUse = useAlt ? BuildReportTool.Window.Settings.LIST_NORMAL_ALT_STYLE_NAME : BuildReportTool.Window.Settings.LIST_NORMAL_STYLE_NAME;

                GUILayout.Label(b.RawSize, styleToUse, GUILayout.MaxWidth(100), GUILayout.Height(30));

                useAlt = !useAlt;
            }
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
Ejemplo n.º 7
0
        static int SortByAssetFullPathAscending(BuildReportTool.SizePart entry1, BuildReportTool.SizePart entry2)
        {
            int result = string.Compare(entry1.Name, entry2.Name, StringComparison.OrdinalIgnoreCase);

            // invert the result
            if (result == 1)
            {
                return(-1);
            }
            if (result == -1)
            {
                return(1);
            }
            return(0);
        }
        static int SortByAssetNameAscending(BuildReportTool.SizePart entry1, BuildReportTool.SizePart entry2)
        {
            int result = string.Compare(entry1.Name, entry2.Name, true);

            // invert the result
            if (result == 1)
            {
                return(-1);
            }
            if (result == -1)
            {
                return(1);
            }

            return(0);
        }
Ejemplo n.º 9
0
        void AddToSize(string buildSizeName, long sizeToAdd)
        {
            if (sizeToAdd == 0)
            {
                return;
            }

            BuildReportTool.SizePart buildSize = BuildSizes.FirstOrDefault(part => part.Name == buildSizeName);

            if (buildSize != null)
            {
                //Debug.LogFormat("{0} size before: {1}", buildSizeName, buildSize.DerivedSize);

                AddToSize(buildSize, sizeToAdd);

                //Debug.LogFormat("{0} size after: {1}", buildSizeName, buildSize.DerivedSize);
            }
        }
Ejemplo n.º 10
0
        void AddToTotalSize(long sizeToAdd)
        {
            if (sizeToAdd == 0)
            {
                return;
            }

            BuildReportTool.SizePart buildSize = BuildSizes.FirstOrDefault(part => part.IsTotal);

            if (buildSize != null)
            {
                //Debug.LogFormat("total size before: {0}", buildSize.DerivedSize);

                AddToSize(buildSize, sizeToAdd);

                UsedTotalSize = buildSize.Size;

                //Debug.LogFormat("total size after: {0}", buildSize.DerivedSize);
            }
        }
Ejemplo n.º 11
0
        void ChangeTotalSize(double newSize)
        {
            if (Math.Abs(newSize) < 0.01)
            {
                return;
            }

            BuildReportTool.SizePart totalSize = BuildSizes.FirstOrDefault(part => part.IsTotal);

            if (totalSize != null)
            {
                Debug.LogFormat("total size before: {0}", totalSize.DerivedSize);

                totalSize.DerivedSize = newSize;
                totalSize.Size        = BuildReportTool.Util.GetBytesReadable(totalSize.DerivedSize);

                UsedTotalSize = totalSize.Size;

                Debug.LogFormat("total size after: {0}", totalSize.DerivedSize);
            }
        }
Ejemplo n.º 12
0
	static BuildReportTool.SizePart[] ParseSizePartsFromString(string editorLogPath)
	{
		// now parse the build parts to an array of `BuildReportTool.SizePart`
		List<BuildReportTool.SizePart> buildSizes = new List<BuildReportTool.SizePart>();


		const string SIZE_PARTS_KEY = "Textures      ";

		foreach (string line in DldUtil.BigFileReader.ReadFile(editorLogPath, SIZE_PARTS_KEY))
		{
			// blank line signifies end of dll list
			if (string.IsNullOrEmpty(line) || line == "\n" || line == "\r\n")
			{
				break;
			}
			//Debug.Log("ParseSizePartsFromString: " + line);

			string b = line;

			string gotName = "???";
			string gotSize = "?";
			string gotPercent = "?";

			Match match = Regex.Match(b, @"^[a-z \t]+[^0-9]", RegexOptions.IgnoreCase);
			if (match.Success)
			{
				gotName = match.Groups[0].Value;
				gotName = gotName.Trim();
				if (gotName == "Scripts") gotName = "Script DLLs";
				//Debug.Log("    name? " + gotName);
			}

			match = Regex.Match(b, @"[0-9.]+ (kb|mb|b|gb)", RegexOptions.IgnoreCase);
			if (match.Success)
			{
				gotSize = match.Groups[0].Value.ToUpper();
				//Debug.Log("    size? " + gotSize);
			}

			match = Regex.Match(b, @"[0-9.]+%", RegexOptions.IgnoreCase);
			if (match.Success)
			{
				gotPercent = match.Groups[0].Value;
				gotPercent = gotPercent.Substring(0, gotPercent.Length-1);
				//Debug.Log("    percent? " + gotPercent);
			}

			BuildReportTool.SizePart inPart = new BuildReportTool.SizePart();
			inPart.Name = gotName;
			inPart.Size = gotSize;
			inPart.Percentage = Double.Parse(gotPercent);
			inPart.DerivedSize = BuildReportTool.Util.GetApproxSizeFromString(gotSize);

			buildSizes.Add(inPart);

			if (line.IndexOf("100.0%") != -1)
			{
				break;
			}
		}

		return buildSizes.ToArray();
	}
Ejemplo n.º 13
0
        void DrawAssetList(Rect position, BuildReportTool.AssetList list, BuildReportTool.FileFilterGroup filter, int length)
        {
            if (list != null)
            {
                if (_searchResults != null && _searchResults.Length == 0)
                {
                    DrawCentralMessage(position, "No search results");
                    return;
                }

                BuildReportTool.SizePart[] assetListToUse;

                var hasSearchResults = _searchResults != null;

                if (hasSearchResults && _searchResults.Length > 0)
                {
                    assetListToUse = _searchResults;
                }
                else
                {
                    assetListToUse = list.GetListToDisplay(filter);
                }

                if (assetListToUse != null)
                {
                    if (assetListToUse.Length == 0)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(10);
                        GUILayout.Label(Labels.NO_FILES_FOR_THIS_CATEGORY_LABEL, BuildReportTool.Window.Settings.INFO_TITLE_STYLE_NAME);
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        EditorGUIUtility.SetIconSize(Vector2.one * ICON_DISPLAY_SIZE);
                        bool useAlt = false;

                        int viewOffset = list.GetViewOffsetForDisplayedList(filter);

                        // if somehow view offset was out of bounds of the SizePart[] array
                        // reset it to zero
                        if (viewOffset >= assetListToUse.Length)
                        {
                            list.SetViewOffsetForDisplayedList(filter, 0);
                            viewOffset = 0;
                        }

                        int len = Mathf.Min(viewOffset + length, assetListToUse.Length);



                        GUILayout.BeginHorizontal();


                        // --------------------------------------------------------------------------------------------------------
                        // column: asset path and name
                        GUILayout.BeginVertical();
                        useAlt = false;

                        //GUILayout.Box("", BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_STYLE_NAME, GUILayout.Height(LIST_HEIGHT), GUILayout.Width(position.width));

                        GUILayout.BeginHorizontal();


                        string sortTypeAssetFullPathStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_STYLE_NAME;
                        if (!hasSearchResults && list.CurrentSortType == BuildReportTool.AssetList.SortType.AssetFullPath)
                        {
                            if (list.CurrentSortOrder == BuildReportTool.AssetList.SortOrder.Descending)
                            {
                                sortTypeAssetFullPathStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_DESC_STYLE_NAME;
                            }
                            else
                            {
                                sortTypeAssetFullPathStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_ASC_STYLE_NAME;
                            }
                        }
                        if (GUILayout.Button("Asset Path", sortTypeAssetFullPathStyleName, GUILayout.Height(LIST_HEIGHT)) && !hasSearchResults)
                        {
                            list.ToggleSort(BuildReportTool.AssetList.SortType.AssetFullPath);
                        }


                        string sortTypeAssetFilenameStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_STYLE_NAME;
                        if (!hasSearchResults && list.CurrentSortType == BuildReportTool.AssetList.SortType.AssetFilename)
                        {
                            if (list.CurrentSortOrder == BuildReportTool.AssetList.SortOrder.Descending)
                            {
                                sortTypeAssetFilenameStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_DESC_STYLE_NAME;
                            }
                            else
                            {
                                sortTypeAssetFilenameStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_ASC_STYLE_NAME;
                            }
                        }
                        if (GUILayout.Button("Asset Filename", sortTypeAssetFilenameStyleName, GUILayout.Height(LIST_HEIGHT)) && !hasSearchResults)
                        {
                            list.ToggleSort(BuildReportTool.AssetList.SortType.AssetFilename);
                        }
                        GUILayout.EndHorizontal();


                        // --------------------------------------------------------------------------------------------------------

                        _assetListScrollPos = GUILayout.BeginScrollView(_assetListScrollPos, BuildReportTool.Window.Settings.HIDDEN_SCROLLBAR_STYLE_NAME, BuildReportTool.Window.Settings.HIDDEN_SCROLLBAR_STYLE_NAME);

                        for (int n = viewOffset; n < len; ++n)
                        {
                            BuildReportTool.SizePart b = assetListToUse[n];

                            string styleToUse  = useAlt ? BuildReportTool.Window.Settings.LIST_SMALL_ALT_STYLE_NAME : BuildReportTool.Window.Settings.LIST_SMALL_STYLE_NAME;
                            bool   inSumSelect = list.InSumSelection(b);
                            if (inSumSelect)
                            {
                                styleToUse = BuildReportTool.Window.Settings.LIST_SMALL_SELECTED_NAME;
                            }

                            GUILayout.BeginHorizontal();

                            if (b.Name.StartsWith("Assets/"))
                            {
                                if (GUILayout.Button("Ping", GUILayout.Width(37)))
                                {
                                    Utility.PingAssetInProject(b.Name);
                                }
                            }
                            else
                            {
                                GUILayout.Space(37);
                            }


                            // the asset name
                            Texture icon = AssetDatabase.GetCachedIcon(b.Name);

                            string prettyName = string.Empty;

                            prettyName = string.Format(" {0}. <color=#{1}>{2}{3}</color><b>{4}</b>", (n + 1), GetPathColor(inSumSelect), BuildReportTool.Util.GetAssetPath(b.Name), BuildReportTool.Util.GetAssetPathToNameSeparator(b.Name), BuildReportTool.Util.GetAssetFilename(b.Name));



                            GUIStyle styleObjToUse = GUI.skin.GetStyle(styleToUse);
                            Color    temp          = styleObjToUse.normal.textColor;
                            int      origLeft      = styleObjToUse.padding.left;
                            int      origRight     = styleObjToUse.padding.right;

                            styleObjToUse.normal.textColor = styleObjToUse.onNormal.textColor;
                            styleObjToUse.padding.right    = 0;

                            if (icon == null)
                            {
                                //GUILayout.BeginHorizontal(styleObjToUse);
                                GUILayout.Space(24);
                                //GUILayout.EndHorizontal();
                            }

                            styleObjToUse.normal.textColor = temp;
                            styleObjToUse.padding.left     = 2;
                            if (GUILayout.Button(new GUIContent(prettyName, icon), styleObjToUse, GUILayout.Height(LIST_HEIGHT)))
                            {
                                if (Event.current.control)
                                {
                                    if (!inSumSelect)
                                    {
                                        list.AddToSumSelection(b);
                                        _lastClickedEntryIdx = n;
                                    }
                                    else
                                    {
                                        list.ToggleSumSelection(b);
                                        _lastClickedEntryIdx = -1;
                                    }
                                }
                                else if (Event.current.shift)
                                {
                                    if (_lastClickedEntryIdx != -1)
                                    {
                                        // select all from last clicked to here
                                        if (_lastClickedEntryIdx < n)
                                        {
                                            for (int addToSelectIdx = _lastClickedEntryIdx; addToSelectIdx <= n; ++addToSelectIdx)
                                            {
                                                list.AddToSumSelection(assetListToUse[addToSelectIdx]);
                                            }
                                        }
                                        else if (_lastClickedEntryIdx > n)
                                        {
                                            for (int addToSelectIdx = n; addToSelectIdx <= _lastClickedEntryIdx; ++addToSelectIdx)
                                            {
                                                list.AddToSumSelection(assetListToUse[addToSelectIdx]);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        list.AddToSumSelection(b);
                                    }

                                    _lastClickedEntryIdx = n;
                                }
                                else
                                {
                                    list.ClearSelection();
                                    list.AddToSumSelection(b);
                                    _lastClickedEntryIdx = n;
                                }
                            }
                            styleObjToUse.padding.right = origRight;
                            styleObjToUse.padding.left  = origLeft;


                            GUILayout.EndHorizontal();

                            useAlt = !useAlt;
                        }


                        GUILayout.Space(SCROLLBAR_BOTTOM_PADDING);

                        GUILayout.EndScrollView();

                        GUILayout.EndVertical();



                        bool pressedRawSizeSortBtn = false;
                        bool pressedImpSizeSortBtn = false;

                        bool pressedSizeBeforeBuildSortBtn = false;

                        // --------------------------------------------------------------------------------------------------------
                        // column: raw file size


                        if (IsShowingUsedAssets && (assetListToUse[0].SizeInAssetsFolderBytes != -1))
                        {
                            pressedSizeBeforeBuildSortBtn = DrawColumn(viewOffset, len, BuildReportTool.AssetList.SortType.SizeBeforeBuild, "Size Before Build   ", !hasSearchResults, false,
                                                                       list, assetListToUse, (b) => b.SizeInAssetsFolder, ref _assetListScrollPos);
                        }

                        if (IsShowingUsedAssets && BuildReportTool.Options.ShowImportedSizeForUsedAssets)
                        {
                            pressedRawSizeSortBtn = DrawColumn(viewOffset, len, BuildReportTool.AssetList.SortType.ImportedSizeOrRawSize, "Size In Build", !hasSearchResults, false,
                                                               list, assetListToUse, (b) =>
                            {
                                // assets in the "StreamingAssets" folder do not have an imported size
                                // in those cases, the raw size is the same as the imported size
                                // so just use the raw size
                                if (b.ImportedSize == "N/A")
                                {
                                    return(b.RawSize);
                                }

                                return(b.ImportedSize);
                            }, ref _assetListScrollPos);
                        }

                        if (IsShowingUnusedAssets || (IsShowingUsedAssets && !BuildReportTool.Options.ShowImportedSizeForUsedAssets))
                        {
                            pressedRawSizeSortBtn = DrawColumn(viewOffset, len, BuildReportTool.AssetList.SortType.RawSize, (IsShowingUnusedAssets ? "Raw Size" : "Size In Build"), !hasSearchResults, false,
                                                               list, assetListToUse, (b) => b.RawSize, ref _assetListScrollPos);
                        }


                        bool showScrollbarForImportedSize = IsShowingUnusedAssets;


                        // --------------------------------------------------------------------------------------------------------
                        // column: imported file size


                        if (IsShowingUnusedAssets)
                        {
                            pressedImpSizeSortBtn = DrawColumn(viewOffset, len, BuildReportTool.AssetList.SortType.ImportedSize, "Imported Size   ", !hasSearchResults, showScrollbarForImportedSize,
                                                               list, assetListToUse, (b) => b.ImportedSize, ref _assetListScrollPos);
                        }


                        // --------------------------------------------------------------------------------------------------------
                        // column: percentage to total size

                        bool pressedPercentSortBtn = false;

                        if (IsShowingUsedAssets)
                        {
                            pressedPercentSortBtn = DrawColumn(viewOffset, len, BuildReportTool.AssetList.SortType.PercentSize, "Percent   ", !hasSearchResults, true,
                                                               list, assetListToUse, (b) => {
                                string text = b.Percentage + "%";
                                if (b.Percentage < 0)
                                {
                                    text = Labels.NON_APPLICABLE_PERCENTAGE_LABEL;
                                }
                                return(text);
                            }, ref _assetListScrollPos);
                        }

                        // --------------------------------------------------------------------------------------------------------

                        if (!hasSearchResults)
                        {
                            if (pressedRawSizeSortBtn)
                            {
                                var sortType = BuildReportTool.AssetList.SortType.RawSize;
                                if (IsShowingUsedAssets && BuildReportTool.Options.ShowImportedSizeForUsedAssets)
                                {
                                    sortType = BuildReportTool.AssetList.SortType.ImportedSizeOrRawSize;
                                }
                                list.ToggleSort(sortType);
                            }
                            else if (pressedSizeBeforeBuildSortBtn)
                            {
                                list.ToggleSort(BuildReportTool.AssetList.SortType.SizeBeforeBuild);
                            }
                            else if (pressedImpSizeSortBtn)
                            {
                                list.ToggleSort(BuildReportTool.AssetList.SortType.ImportedSize);
                            }
                            else if (pressedPercentSortBtn)
                            {
                                list.ToggleSort(BuildReportTool.AssetList.SortType.PercentSize);
                            }
                        }


                        GUILayout.EndHorizontal();
                    }
                }
            }
        }
Ejemplo n.º 14
0
        void InitiateDeleteAllUnused(BuildInfo buildReportToDisplay)
        {
            BuildReportTool.AssetList  list = buildReportToDisplay.UnusedAssets;
            BuildReportTool.SizePart[] all  = list.All;

            int filesToDeleteCount = 0;

            for (int n = 0, len = all.Length; n < len; ++n)
            {
                BuildReportTool.SizePart b = all[n];

                bool okToDelete = BuildReportTool.Util.IsFileOkForDeleteAllOperation(b.Name);

                if (okToDelete)
                {
                    //Debug.Log("added " + b.Name + " for deletion");
                    ++filesToDeleteCount;
                }
            }

            if (filesToDeleteCount == 0)
            {
                const string NOTHING_TO_DELETE =
                    "Take note that for safety, Build Report Tool assets, Unity editor assets, version control metadata, and Unix-style hidden files will not be included for deletion.\n\nYou can force deleting them by selecting them (via the checkbox) and using \"Delete selected\", or simply delete them the normal way in your project view.";

                EditorApplication.Beep();
                EditorUtility.DisplayDialog("Nothing to delete!", NOTHING_TO_DELETE, "Ok");
                return;
            }

            string plural = "";

            if (filesToDeleteCount > 1)
            {
                plural = "s";
            }

            EditorApplication.Beep();
            if (!EditorUtility.DisplayDialog("Delete?",
                                             string.Format("Among {0} file{1} in your project, {2} will be deleted.\n\nBuild Report Tool assets themselves, Unity editor assets, version control metadata, and Unix-style hidden files will not be included for deletion. You can force-delete those by selecting them (via the checkbox) and use \"Delete selected\", or simply delete them the normal way in your project view.\n\nDeleting a large number of files may take a long time as Unity will rebuild the project's Library folder.\n\nAre you sure about this?\n\nThe file{1} can be recovered from your {3}.",
                                                           all.Length.ToString(), plural, filesToDeleteCount.ToString(), BuildReportTool.Util.NameOfOSTrashFolder), "Yes", "No"))
            {
                return;
            }

            List <BuildReportTool.SizePart> newAll = new List <BuildReportTool.SizePart>();

            int deletedCount = 0;

            for (int n = 0, len = all.Length; n < len; ++n)
            {
                BuildReportTool.SizePart b = all[n];

                bool okToDelete = BuildReportTool.Util.IsFileOkForDeleteAllOperation(b.Name);

                if (okToDelete)
                {
                    // delete this
                    if (BuildReportTool.Util.ShowFileDeleteProgress(deletedCount, filesToDeleteCount, b.Name, true))
                    {
                        return;
                    }

                    BuildReportTool.Util.DeleteSizePartFile(b);
                    ++deletedCount;
                }
                else
                {
                    //Debug.Log("added " + b.Name + " to new list");
                    newAll.Add(b);
                }
            }

            EditorUtility.ClearProgressBar();

            BuildReportTool.SizePart[] newAllArr = newAll.ToArray();

            BuildReportTool.SizePart[][] perCategoryUnused =
                BuildReportTool.ReportGenerator.SegregateAssetSizesPerCategory(newAllArr, buildReportToDisplay.FileFilters);

            list.Reinit(newAllArr, perCategoryUnused,
                        IsShowingUsedAssets
                                        ? BuildReportTool.Options.NumberOfTopLargestUsedAssetsToShow
                                        : BuildReportTool.Options.NumberOfTopLargestUnusedAssetsToShow);
            list.ClearSelection();


            string finalMessage = string.Format("{0} file{1} removed from your project. They can be recovered from your {2}.",
                                                filesToDeleteCount.ToString(), plural, BuildReportTool.Util.NameOfOSTrashFolder);

            Debug.LogWarning(finalMessage);

            EditorApplication.Beep();
            EditorUtility.DisplayDialog("Delete successful", finalMessage, "OK");
        }
Ejemplo n.º 15
0
        void InitiateDeleteSelectedInAssetList(BuildInfo buildReportToDisplay, BuildReportTool.AssetList listToDeleteFrom)
        {
            if (listToDeleteFrom.IsNothingSelected)
            {
                return;
            }


            BuildReportTool.SizePart[] all = listToDeleteFrom.All;

            int numOfFilesRequestedToDelete = listToDeleteFrom.GetSelectedCount();
            int numOfFilesToDelete          = numOfFilesRequestedToDelete;
            int systemDeletionFileCount     = 0;
            int brtFilesSelectedForDelete   = 0;


            // filter out files that shouldn't be deleted
            // and identify unrecoverable files
            for (int n = 0, len = all.Length; n < len; ++n)
            {
                BuildReportTool.SizePart b = all[n];
                bool isThisFileToBeDeleted = listToDeleteFrom.InSumSelection(b);

                if (isThisFileToBeDeleted)
                {
                    if (BuildReportTool.Util.IsFileInBuildReportFolder(b.Name) &&
                        !BuildReportTool.Util.IsUselessFile(b.Name))
                    {
                        //Debug.Log("BRT file? " + b.Name);
                        --numOfFilesToDelete;
                        ++brtFilesSelectedForDelete;
                    }
                    else if (BuildReportTool.Util.HaveToUseSystemForDelete(b.Name))
                    {
                        ++systemDeletionFileCount;
                    }
                }
            }

            if (numOfFilesToDelete <= 0)
            {
                if (brtFilesSelectedForDelete > 0)
                {
                    EditorApplication.Beep();
                    EditorUtility.DisplayDialog("Can't delete!",
                                                "Take note that for safety, Build Report Tool assets themselves will not be included for deletion.",
                                                "OK");
                }

                return;
            }


            // prepare warning message for user

            bool deletingSystemFilesOnly = (systemDeletionFileCount == numOfFilesToDelete);
            bool deleteIsRecoverable     = !deletingSystemFilesOnly;

            string plural = "";

            if (numOfFilesToDelete > 1)
            {
                plural = "s";
            }

            string message;

            if (numOfFilesRequestedToDelete != numOfFilesToDelete)
            {
                message = "Among " + numOfFilesRequestedToDelete + " file" + plural + " requested to be deleted, only " +
                          numOfFilesToDelete + " will be deleted.";
            }
            else
            {
                message = "This will delete " + numOfFilesToDelete + " asset" + plural + " in your project.";
            }

            // add warning about BRT files that are skipped
            if (brtFilesSelectedForDelete > 0)
            {
                message += "\n\nTake note that for safety, " + brtFilesSelectedForDelete + " file" +
                           ((brtFilesSelectedForDelete > 1) ? "s" : "") +
                           " found to be Build Report Tool assets are not included for deletion.";
            }

            // add warning about unrecoverable files
            if (systemDeletionFileCount > 0)
            {
                if (deletingSystemFilesOnly)
                {
                    message += "\n\nThe deleted file" + plural + " will not be recoverable from the " +
                               BuildReportTool.Util.NameOfOSTrashFolder + ", unless you have your own backup.";
                }
                else
                {
                    message += "\n\nAmong the " + numOfFilesToDelete + " file" + plural + " for deletion, " +
                               systemDeletionFileCount + " will not be recoverable from the " +
                               BuildReportTool.Util.NameOfOSTrashFolder + ", unless you have your own backup.";
                }

                message +=
                    "\n\nThis is a limitation in Unity and .NET code. To ensure deleting will move the files to the " +
                    BuildReportTool.Util.NameOfOSTrashFolder +
                    " instead, delete your files the usual way using your project view.";
            }
            else
            {
                message += "\n\nThe deleted file" + plural + " can be recovered from your " +
                           BuildReportTool.Util.NameOfOSTrashFolder + ".";
            }

            message +=
                "\n\nDeleting a large number of files may take a long time as Unity will rebuild the project's Library folder.\n\nProceed with deleting?";

            EditorApplication.Beep();
            if (!EditorUtility.DisplayDialog("Delete?", message, "Yes", "No"))
            {
                return;
            }

            List <BuildReportTool.SizePart> allList  = new List <BuildReportTool.SizePart>(all);
            List <BuildReportTool.SizePart> toRemove = new List <BuildReportTool.SizePart>(all.Length / 4);

            // finally, delete the files
            int deletedCount = 0;

            for (int n = 0, len = allList.Count; n < len; ++n)
            {
                BuildReportTool.SizePart b = allList[n];


                bool okToDelete = BuildReportTool.Util.IsUselessFile(b.Name) ||
                                  !BuildReportTool.Util.IsFileInBuildReportFolder(b.Name);

                if (listToDeleteFrom.InSumSelection(b) && okToDelete)
                {
                    // delete this

                    if (BuildReportTool.Util.ShowFileDeleteProgress(deletedCount, numOfFilesToDelete, b.Name,
                                                                    deleteIsRecoverable))
                    {
                        return;
                    }

                    BuildReportTool.Util.DeleteSizePartFile(b);
                    toRemove.Add(b);
                    ++deletedCount;
                }
            }

            EditorUtility.ClearProgressBar();


            // refresh the asset lists
            allList.RemoveAll(i => toRemove.Contains(i));
            BuildReportTool.SizePart[] allWithRemoved = allList.ToArray();

            // recreate per category list (maybe just remove from existing per category lists instead?)
            BuildReportTool.SizePart[][] perCategoryOfList =
                BuildReportTool.ReportGenerator.SegregateAssetSizesPerCategory(allWithRemoved,
                                                                               buildReportToDisplay.FileFilters);

            listToDeleteFrom.Reinit(allWithRemoved, perCategoryOfList,
                                    IsShowingUsedAssets
                                        ? BuildReportTool.Options.NumberOfTopLargestUsedAssetsToShow
                                        : BuildReportTool.Options.NumberOfTopLargestUnusedAssetsToShow);
            listToDeleteFrom.ClearSelection();


            // print info about the delete operation to console
            string finalMessage = string.Format("{0} file{1} removed from your project.", deletedCount.ToString(), plural);

            if (deleteIsRecoverable)
            {
                finalMessage += " They can be recovered from your " + BuildReportTool.Util.NameOfOSTrashFolder + ".";
            }

            EditorApplication.Beep();
            EditorUtility.DisplayDialog("Delete successful", finalMessage, "OK");

            Debug.LogWarning(finalMessage);
        }
Ejemplo n.º 16
0
 public void AddToSumSelection(BuildReportTool.SizePart b)
 {
     _selectedForSum.Add(b.Name, b);
 }
Ejemplo n.º 17
0
        void DrawAssetList(Rect position, BuildReportTool.AssetList list, BuildReportTool.FileFilterGroup filter, int length)
        {
            if (list != null)
            {
                if (_searchResults != null && _searchResults.Length == 0)
                {
                    DrawCentralMessage(position, "No search results");
                    return;
                }

                BuildReportTool.SizePart[] assetListToUse;

                var hasSearchResults = _searchResults != null;

                if (hasSearchResults && _searchResults.Length > 0)
                {
                    assetListToUse = _searchResults;
                }
                else
                {
                    assetListToUse = list.GetListToDisplay(filter);
                }

                if (assetListToUse != null)
                {
                    if (assetListToUse.Length == 0)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(10);
                        GUILayout.Label(Labels.NO_FILES_FOR_THIS_CATEGORY_LABEL, BuildReportTool.Window.Settings.INFO_TITLE_STYLE_NAME);
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        EditorGUIUtility.SetIconSize(Vector2.one * ICON_DISPLAY_SIZE);
                        bool useAlt = false;

                        int viewOffset = list.GetViewOffsetForDisplayedList(filter);

                        // if somehow view offset was out of bounds of the SizePart[] array
                        // reset it to zero
                        if (viewOffset >= assetListToUse.Length)
                        {
                            list.SetViewOffsetForDisplayedList(filter, 0);
                            viewOffset = 0;
                        }

                        int len = Mathf.Min(viewOffset + length, assetListToUse.Length);



                        GUILayout.BeginHorizontal();


                        // --------------------------------------------------------------------------------------------------------
                        // column: asset path and name
                        GUILayout.BeginVertical();
                        useAlt = false;

                        //GUILayout.Box("", BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_STYLE_NAME, GUILayout.Height(LIST_HEIGHT), GUILayout.Width(position.width));

                        GUILayout.BeginHorizontal();


                        string sortTypeAssetFullPathStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_STYLE_NAME;
                        if (!hasSearchResults && list.CurrentSortType == BuildReportTool.AssetList.SortType.AssetFullPath)
                        {
                            if (list.CurrentSortOrder == BuildReportTool.AssetList.SortOrder.Descending)
                            {
                                sortTypeAssetFullPathStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_DESC_STYLE_NAME;
                            }
                            else
                            {
                                sortTypeAssetFullPathStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_ASC_STYLE_NAME;
                            }
                        }
                        if (GUILayout.Button("Asset Path", sortTypeAssetFullPathStyleName, GUILayout.Height(LIST_HEIGHT)) && !hasSearchResults)
                        {
                            list.ToggleSort(BuildReportTool.AssetList.SortType.AssetFullPath);
                        }


                        string sortTypeAssetFilenameStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_STYLE_NAME;
                        if (!hasSearchResults && list.CurrentSortType == BuildReportTool.AssetList.SortType.AssetFilename)
                        {
                            if (list.CurrentSortOrder == BuildReportTool.AssetList.SortOrder.Descending)
                            {
                                sortTypeAssetFilenameStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_DESC_STYLE_NAME;
                            }
                            else
                            {
                                sortTypeAssetFilenameStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_ASC_STYLE_NAME;
                            }
                        }
                        if (GUILayout.Button("Asset Filename", sortTypeAssetFilenameStyleName, GUILayout.Height(LIST_HEIGHT)) && !hasSearchResults)
                        {
                            list.ToggleSort(BuildReportTool.AssetList.SortType.AssetFilename);
                        }
                        GUILayout.EndHorizontal();


                        // --------------------------------------------------------------------------------------------------------

                        _assetListScrollPos = GUILayout.BeginScrollView(_assetListScrollPos, BuildReportTool.Window.Settings.HIDDEN_SCROLLBAR_STYLE_NAME, BuildReportTool.Window.Settings.HIDDEN_SCROLLBAR_STYLE_NAME);

                        for (int n = viewOffset; n < len; ++n)
                        {
                            BuildReportTool.SizePart b = assetListToUse[n];

                            string styleToUse  = useAlt ? BuildReportTool.Window.Settings.LIST_SMALL_ALT_STYLE_NAME : BuildReportTool.Window.Settings.LIST_SMALL_STYLE_NAME;
                            bool   inSumSelect = list.InSumSelection(b);
                            if (inSumSelect)
                            {
                                styleToUse = BuildReportTool.Window.Settings.LIST_SMALL_SELECTED_NAME;
                            }

                            GUILayout.BeginHorizontal();

                            // checkbox for selecting
                            bool newInSumSelect = GUILayout.Toggle(inSumSelect, "", GUILayout.Width(20));
                            if (inSumSelect != newInSumSelect)
                            {
                                if (newInSumSelect)
                                {
                                    list.AddToSumSelection(b);
                                }
                                else
                                {
                                    list.RemoveFromSumSelection(b);
                                }
                            }


                            // the asset name
                            Texture icon = AssetDatabase.GetCachedIcon(b.Name);

                            string prettyName = string.Empty;

                            prettyName = string.Format(" {0}. <color=#{1}>{2}{3}</color><b>{4}</b>", (n + 1), GetPathColor(inSumSelect), BuildReportTool.Util.GetAssetPath(b.Name), BuildReportTool.Util.GetAssetPathToNameSeparator(b.Name), BuildReportTool.Util.GetAssetFilename(b.Name));



                            GUIStyle styleObjToUse = GUI.skin.GetStyle(styleToUse);
                            Color    temp          = styleObjToUse.normal.textColor;
                            int      origLeft      = styleObjToUse.padding.left;
                            int      origRight     = styleObjToUse.padding.right;

                            styleObjToUse.normal.textColor = styleObjToUse.onNormal.textColor;
                            styleObjToUse.padding.right    = 0;

                            if (icon == null)
                            {
                                //GUILayout.BeginHorizontal(styleObjToUse);
                                GUILayout.Space(15);
                                //GUILayout.EndHorizontal();
                            }

                            styleObjToUse.normal.textColor = temp;
                            styleObjToUse.padding.left     = 2;
                            if (GUILayout.Button(new GUIContent(prettyName, icon), styleObjToUse, GUILayout.Height(LIST_HEIGHT)))
                            {
                                Utility.PingAssetInProject(b.Name);
                            }
                            styleObjToUse.padding.right = origRight;
                            styleObjToUse.padding.left  = origLeft;


                            GUILayout.EndHorizontal();

                            useAlt = !useAlt;
                        }

                        GUILayout.EndScrollView();

                        GUILayout.EndVertical();



                        // --------------------------------------------------------------------------------------------------------
                        // column: raw file size
                        bool pressedRawSizeSortBtn = DrawColumn(viewOffset, len, BuildReportTool.AssetList.SortType.RawSize, (IsShowingUnusedAssets ? "Raw Size" : "Size"), !hasSearchResults, false,
                                                                list, assetListToUse, (b) => { return(b.RawSize); }, ref _assetListScrollPos);


                        bool showScrollbarForImportedSize = IsShowingUnusedAssets;


                        // --------------------------------------------------------------------------------------------------------
                        // column: imported file size

                        bool pressedImpSizeSortBtn = false;

                        if (IsShowingUnusedAssets)
                        {
                            pressedImpSizeSortBtn = DrawColumn(viewOffset, len, BuildReportTool.AssetList.SortType.ImportedSize, "Imported Size   ", !hasSearchResults, showScrollbarForImportedSize,
                                                               list, assetListToUse, (b) => { return(b.ImportedSize); }, ref _assetListScrollPos);
                        }


                        // --------------------------------------------------------------------------------------------------------
                        // column: percentage to total size
                        bool pressedPercentSortBtn = false;

                        if (IsShowingUsedAssets)
                        {
                            pressedPercentSortBtn = DrawColumn(viewOffset, len, BuildReportTool.AssetList.SortType.PercentSize, "Percent   ", !hasSearchResults, true,
                                                               list, assetListToUse, (b) => {
                                string text = b.Percentage + "%";
                                if (b.Percentage < 0)
                                {
                                    text = Labels.NON_APPLICABLE_PERCENTAGE_LABEL;
                                }
                                return(text);
                            }, ref _assetListScrollPos);
                        }

                        // --------------------------------------------------------------------------------------------------------

                        if (!hasSearchResults)
                        {
                            if (pressedRawSizeSortBtn)
                            {
                                list.ToggleSort(BuildReportTool.AssetList.SortType.RawSize);
                            }
                            else if (pressedImpSizeSortBtn)
                            {
                                list.ToggleSort(BuildReportTool.AssetList.SortType.ImportedSize);
                            }
                            else if (pressedPercentSortBtn)
                            {
                                list.ToggleSort(BuildReportTool.AssetList.SortType.PercentSize);
                            }
                        }


                        GUILayout.EndHorizontal();
                    }
                }
            }
        }
Ejemplo n.º 18
0
 public void RemoveFromSumSelection(BuildReportTool.SizePart b)
 {
     _selectedForSum.Remove(b.Name);
 }
Ejemplo n.º 19
0
	static List<BuildReportTool.SizePart> ParseAssetSizesFromEditorLog(string editorLogPath, string[] prefabsUsedInScenes)
	{
		List<BuildReportTool.SizePart> assetSizes = new List<BuildReportTool.SizePart>();
		Dictionary<string, bool> prefabsInBuildDict = new Dictionary<string, bool>();



		long importedSizeBytes = -1;

		// note: list gotten from editor log is already sorted by raw size, descending

		foreach (string line in DldUtil.BigFileReader.ReadFile(_lastEditorLogPath, ASSET_SIZES_KEY))
		{
			if (string.IsNullOrEmpty(line) || line == "\n" || line == "\r\n")
			{
				break;
			}
			if (line.IndexOf(ASSET_SIZES_KEY) != -1)
			{
				continue;
			}

			Match match = Regex.Match(line, @"^ [0-9].*[a-z0-9) ]$", RegexOptions.IgnoreCase);
			if (match.Success)
			{
				// it's an asset entry. parse it
				//string b = match.Groups[0].Value;

				string gotName = "???";
				string gotSize = "?";
				string gotPercent = "?";

				match = Regex.Match(line, @"Assets/.+", RegexOptions.IgnoreCase);
				if (match.Success)
				{
					gotName = match.Groups[0].Value;
					gotName = gotName.Trim();
					//Debug.Log("    name? " + gotName);
				}
				else
				{
					match = Regex.Match(line, @"Built-in.+:.+", RegexOptions.IgnoreCase);
					if (match.Success)
					{
						gotName = match.Groups[0].Value;
						gotName = gotName.Trim();
						//Debug.Log("    built-in?: " + gotName);
					}
					else
					{
						match = Regex.Match(line, @"Resources/.+", RegexOptions.IgnoreCase);
						if (match.Success)
						{
							gotName = match.Groups[0].Value;
							gotName = gotName.Trim();
							//Debug.Log("    built-in?: " + gotName);
						}
						else
						{
							match = Regex.Match(line, @"UnityExtensions/.+", RegexOptions.IgnoreCase);
							if (match.Success)
							{
								gotName = match.Groups[0].Value;
								gotName = gotName.Trim();
								//Debug.Log("    extension?: " + gotName);
							}
						}
					}
				}

				match = Regex.Match(line, @"[0-9.]+ (kb|mb|b|gb)", RegexOptions.IgnoreCase);
				if (match.Success)
				{
					gotSize = match.Groups[0].Value.ToUpper();
					//Debug.Log("    size? " + gotSize);
				}
				else
				{
					Debug.Log("didn't find size for :" + line);
				}

				match = Regex.Match(line, @"[0-9.]+%", RegexOptions.IgnoreCase);
				if (match.Success)
				{
					gotPercent = match.Groups[0].Value;
					gotPercent = gotPercent.Substring(0, gotPercent.Length-1);
					//Debug.Log("    percent? " + gotPercent);
				}
				else
				{
					Debug.Log("didn't find percent for :" + line);
				}
				//Debug.Log("got: " + gotName + " size: " + gotSize);

				BuildReportTool.SizePart inPart = new BuildReportTool.SizePart();
				inPart.Name = System.Security.SecurityElement.Escape(gotName);
				inPart.Size = gotSize;
				inPart.SizeBytes = -1;
				inPart.DerivedSize = BuildReportTool.Util.GetApproxSizeFromString(gotSize);
				inPart.Percentage = Double.Parse(gotPercent);


				// since this is a used asset, the size we got from the editor log *is* already the imported size
				// so don't bother computing imported size.
				importedSizeBytes = -1;
				//importedSizeBytes = BRT_LibCacheUtil.GetImportedFileSize(gotName);
				inPart.ImportedSizeBytes = importedSizeBytes;
				inPart.ImportedSize = BuildReportTool.Util.GetBytesReadable(importedSizeBytes);

				assetSizes.Add(inPart);

				if (gotName.EndsWith(".prefab"))
				{
					prefabsInBuildDict.Add(gotName, false);
				}
			}
			else
			{
				break;
			}
		}

		// include prefabs that are instantiated in scenes (they are not by default)
		//Debug.Log("addInfo.PrefabsUsedInScenes: " + addInfo.PrefabsUsedInScenes.Length);
		foreach (string p in prefabsUsedInScenes)
		{
			if (p.IndexOf("/Resources/") != -1) continue; // prefabs in resources folder are already included in the editor log build info
			if (prefabsInBuildDict.ContainsKey(p)) continue; // if already in assetSizes, continue

			BuildReportTool.SizePart inPart = new BuildReportTool.SizePart();
			inPart.Name = p;
			inPart.Size = "N/A";
			inPart.Percentage = -1;

			//Debug.Log("   prefab added in used assets: " + p);

			assetSizes.Add(inPart);
		}

		return assetSizes;
	}
Ejemplo n.º 20
0
	public static BuildReportTool.SizePart[][] SegregateAssetSizesPerCategory(BuildReportTool.SizePart[] assetSizesAll, FileFilterGroup filters)
	{
		if (assetSizesAll == null || assetSizesAll.Length == 0) return null;

		// we do filters.Count+1 for Unrecognized category
		List< List<BuildReportTool.SizePart> > ret = new List< List<BuildReportTool.SizePart> >(filters.Count+1);
		for (int n = 0, len = filters.Count+1; n < len; ++n)
		{
			ret.Add(new List<BuildReportTool.SizePart>());
		}

		bool foundAtLeastOneMatch = false;
		for (int idxAll = 0, lenAll = assetSizesAll.Length; idxAll < lenAll; ++idxAll)
		{
			BRT_BuildReportWindow.GetValueMessage = "Segregating assets " + (idxAll+1) + " of " + assetSizesAll.Length + "...";

			foundAtLeastOneMatch = false;
			for (int n = 0, len = filters.Count; n < len; ++n)
			{
				if (filters[n].IsFileInFilter(assetSizesAll[idxAll].Name))
				{
					foundAtLeastOneMatch = true;
					ret[n].Add(assetSizesAll[idxAll]);
				}
			}

			if (!foundAtLeastOneMatch)
			{
				ret[ret.Count-1].Add(assetSizesAll[idxAll]);
			}
		}

		BRT_BuildReportWindow.GetValueMessage = "";

		BuildReportTool.SizePart[][] retArr = new BuildReportTool.SizePart[filters.Count+1][];
		for (int n = 0, len = filters.Count+1; n < len; ++n)
		{
			retArr[n] = ret[n].ToArray();
		}

		return retArr;
	}
Ejemplo n.º 21
0
        void DrawAssetList(BuildReportTool.AssetList assetList, bool usedAssets, BuildInfo buildReportToDisplay,
                           AssetDependencies assetDependencies)
        {
            if (assetList == null || assetList.TopLargest == null)
            {
                //Debug.LogError("no top ten largest");
                return;
            }

            BuildReportTool.SizePart[] assetsToShow = assetList.TopLargest;

            if (assetsToShow == null)
            {
                //Debug.LogError("no top ten largest");
                return;
            }

            bool useAlt = true;

            var newEntryHoveredIdx = -1;

            BuildReportTool.SizePart newEntryHovered = null;
            Rect newEntryHoveredRect = new Rect();
            Rect iconRect            = new Rect();
            var  hoveringOverIcon    = false;

            //var hoveringOverLabel = false;

            GUILayout.BeginHorizontal();

            // 1st column: name
            GUILayout.BeginVertical();
            for (int n = 0; n < assetsToShow.Length; ++n)
            {
                BuildReportTool.SizePart b = assetsToShow[n];

                string styleToUse = useAlt
                                                            ? BuildReportTool.Window.Settings.LIST_NORMAL_ALT_STYLE_NAME
                                                            : BuildReportTool.Window.Settings.LIST_NORMAL_STYLE_NAME;
                string iconStyleToUse = useAlt
                                                                ? BuildReportTool.Window.Settings.LIST_ICON_ALT_STYLE_NAME
                                                                : BuildReportTool.Window.Settings.LIST_ICON_STYLE_NAME;

                Texture icon = AssetDatabase.GetCachedIcon(b.Name);

                GUILayout.BeginHorizontal();
                if (icon == null)
                {
                    // no icon, just add space so it aligns with the other entries
                    GUILayout.Label(string.Empty, iconStyleToUse, GUILayout.Width(28), GUILayout.Height(30));
                }
                else
                {
                    GUILayout.Button(icon, iconStyleToUse, GUILayout.Width(28), GUILayout.Height(30));
                }

                if (Event.current.type == EventType.Repaint)
                {
                    iconRect = GUILayoutUtility.GetLastRect();

                    // if mouse is hovering over asset entry's icon (not the label)
                    // draw a border on the asset icon
                    if (iconRect.Contains(Event.current.mousePosition))
                    {
                        hoveringOverIcon    = true;
                        newEntryHoveredIdx  = n;
                        newEntryHovered     = b;
                        newEntryHoveredRect = iconRect;

                        GUI.Box(iconRect, icon, "IconHovered");
                    }
                }

                string prettyName = string.Format(" {0}. {1}", (n + 1).ToString(), BuildReportTool.Util.GetAssetFilename(b.Name));
                if (GUILayout.Button(prettyName, styleToUse, GUILayout.MinWidth(100), GUILayout.MaxWidth(400),
                                     GUILayout.Height(30)))
                {
                    Utility.PingAssetInProject(b.Name);
                }

                if (newEntryHoveredIdx == -1 && Event.current.type == EventType.Repaint)
                {
                    var labelRect = GUILayoutUtility.GetLastRect();

                    // if mouse is hovering over asset entry's label
                    // draw a border on the asset icon
                    if (labelRect.Contains(Event.current.mousePosition))
                    {
                        //hoveringOverLabel = true;
                        newEntryHoveredIdx  = n;
                        newEntryHovered     = b;
                        newEntryHoveredRect = labelRect;

                        GUI.Box(iconRect, icon, "IconHovered");
                    }
                }

                GUILayout.EndHorizontal();

                useAlt = !useAlt;
            }

            GUILayout.EndVertical();


            if (Event.current.type == EventType.Repaint)
            {
                if (usedAssets)
                {
                    _assetUsedEntryHoveredIdx = newEntryHoveredIdx;
                }
                else
                {
                    _assetUnusedEntryHoveredIdx = newEntryHoveredIdx;
                }

                if (newEntryHoveredIdx != -1)
                {
                    string hoveredAssetPath = newEntryHovered != null ? newEntryHovered.Name : null;

                    // ----------------
                    // update what is considered the hovered asset, for use later on
                    // when the tooltip will be drawn
                    BRT_BuildReportWindow.UpdateHoveredAsset(hoveredAssetPath, newEntryHoveredRect,
                                                             usedAssets, buildReportToDisplay, assetDependencies);

                    // ----------------
                    // if mouse is hovering over the correct area, we signify that
                    // the tooltip thumbnail should be drawn
                    if (BuildReportTool.Options.ShowTooltipThumbnail &&
                        (BuildReportTool.Options.ShowThumbnailOnHoverLabelToo || hoveringOverIcon) &&
                        BRT_BuildReportWindow.GetAssetPreview(hoveredAssetPath) != null)
                    {
                        _shouldShowThumbnailOnHoveredAsset = true;
                    }
                    else
                    {
                        _shouldShowThumbnailOnHoveredAsset = false;
                    }
                }
            }

            // 2nd column: size

            var useRawSize = (usedAssets && !BuildReportTool.Options.ShowImportedSizeForUsedAssets) || !usedAssets;

            useAlt = true;
            GUILayout.BeginVertical();
            for (int n = 0; n < assetsToShow.Length; ++n)
            {
                BuildReportTool.SizePart b = assetsToShow[n];

                string styleToUse = useAlt
                                                            ? BuildReportTool.Window.Settings.LIST_NORMAL_ALT_STYLE_NAME
                                                            : BuildReportTool.Window.Settings.LIST_NORMAL_STYLE_NAME;

                GUILayout.Label(useRawSize ? b.RawSize : b.ImportedSize, styleToUse, GUILayout.MaxWidth(100),
                                GUILayout.Height(30));

                useAlt = !useAlt;
            }

            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
Ejemplo n.º 22
0
        static int SortByAssetNameDescending(BuildReportTool.SizePart entry1, BuildReportTool.SizePart entry2)
        {
            int result = string.Compare(entry1.Name, entry2.Name, true);

            return(result);
        }
Ejemplo n.º 23
0
	public static BuildReportTool.SizePart CreateSizePartFromFile(string filename, string fileFullPath)
	{
		BuildReportTool.SizePart outPart = new BuildReportTool.SizePart();

		outPart.Name = System.Security.SecurityElement.Escape(filename);

		if (File.Exists(fileFullPath))
		{
			long fileSizeBytes = GetFileSizeInBytes(fileFullPath);
			outPart.RawSizeBytes = fileSizeBytes;
			outPart.RawSize = GetBytesReadable(fileSizeBytes);


			long importedSizeBytes = -1;
			//importedSizeBytes = BRT_LibCacheUtil.GetImportedFileSize(filename);

			outPart.ImportedSizeBytes = importedSizeBytes;
			outPart.ImportedSize = BuildReportTool.Util.GetBytesReadable(importedSizeBytes);
		}
		else
		{
			outPart.RawSizeBytes = -1;
			outPart.RawSize = "???";
		}

		/// \todo perhaps compute percentage: file size of this DLL out of total build size (would need to convert string of total build size into an int of bytes)
		outPart.Percentage = -1;

		return outPart;
	}
Ejemplo n.º 24
0
        // Sum Selection: Queries
        // --------------------------------------------------------------------

        public bool InSumSelection(BuildReportTool.SizePart b)
        {
            return(_selectedForSum.ContainsKey(b.Name));
        }
Ejemplo n.º 25
0
        void DrawAssetList(BuildReportTool.AssetList assetList, bool usedAssets)
        {
            BuildReportTool.SizePart[] assetsToShow = assetList.TopLargest;

            if (assetsToShow == null)
            {
                //Debug.LogError("no top ten largest");
                return;
            }

            bool useAlt = true;

            GUILayout.BeginHorizontal();

            // 1st column: name
            GUILayout.BeginVertical();
            for (int n = 0; n < assetsToShow.Length; ++n)
            {
                BuildReportTool.SizePart b = assetsToShow[n];

                string styleToUse     = useAlt ? BuildReportTool.Window.Settings.LIST_NORMAL_ALT_STYLE_NAME : BuildReportTool.Window.Settings.LIST_NORMAL_STYLE_NAME;
                string iconStyleToUse = useAlt ? BuildReportTool.Window.Settings.LIST_ICON_ALT_STYLE_NAME : BuildReportTool.Window.Settings.LIST_ICON_STYLE_NAME;

                string  prettyName = " " + (n + 1) + ". " + Path.GetFileName(b.Name);
                Texture icon       = AssetDatabase.GetCachedIcon(b.Name);

                GUILayout.BeginHorizontal();
                if (icon == null)
                {
                    //GUILayout.Space(22);
                    GUILayout.Label(string.Empty, iconStyleToUse, GUILayout.Width(28), GUILayout.Height(30));
                }
                else
                {
                    GUILayout.Button(icon, iconStyleToUse, GUILayout.Width(28), GUILayout.Height(30));
                }
                if (GUILayout.Button(prettyName, styleToUse, GUILayout.MinWidth(100), GUILayout.MaxWidth(400), GUILayout.Height(30)))
                {
                    Utility.PingAssetInProject(b.Name);
                }
                GUILayout.EndHorizontal();

                useAlt = !useAlt;
            }
            GUILayout.EndVertical();

            // 2nd column: size

            var useRawSize = (usedAssets && !BuildReportTool.Options.ShowImportedSizeForUsedAssets) || !usedAssets;

            useAlt = true;
            GUILayout.BeginVertical();
            for (int n = 0; n < assetsToShow.Length; ++n)
            {
                BuildReportTool.SizePart b = assetsToShow[n];

                string styleToUse = useAlt ? BuildReportTool.Window.Settings.LIST_NORMAL_ALT_STYLE_NAME : BuildReportTool.Window.Settings.LIST_NORMAL_STYLE_NAME;

                GUILayout.Label(useRawSize ? b.RawSize : b.ImportedSize, styleToUse, GUILayout.MaxWidth(100), GUILayout.Height(30));

                useAlt = !useAlt;
            }
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
Ejemplo n.º 26
0
        static int SortByAssetFullPathDescending(BuildReportTool.SizePart entry1, BuildReportTool.SizePart entry2)
        {
            int result = string.Compare(entry1.Name, entry2.Name, StringComparison.OrdinalIgnoreCase);

            return(result);
        }