void DrawAssetList(BuildReportTool.AssetList list, BuildReportTool.FileFilterGroup filter, int length)
	{
		GUILayout.BeginHorizontal();
			GUILayout.Label(ASSET_SIZE_BREAKDOWN_MSG_PRE_BOLD, INFO_SUBTITLE_STYLE_NAME);
			GUILayout.Label(ASSET_SIZE_BREAKDOWN_MSG_BOLD, INFO_SUBTITLE_BOLD_STYLE_NAME);
			GUILayout.Label(ASSET_SIZE_BREAKDOWN_MSG_POST_BOLD, INFO_SUBTITLE_STYLE_NAME);
			GUILayout.FlexibleSpace();
		GUILayout.EndHorizontal();

		if (list != null)
		{
			BuildReportTool.SizePart[] assetListToUse = list.GetListToDisplay(filter);

			if (assetListToUse != null)
			{
				if (assetListToUse.Length == 0)
				{
					GUILayout.Label(NO_FILES_FOR_THIS_CATEGORY, INFO_TITLE_STYLE_NAME);
				}
				else
				{
					const int LIST_HEIGHT = 20;
					const int ICON_DISPLAY_SIZE = 15;
					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();

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

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

							GUILayout.BeginHorizontal();
								bool newInSumSelect = GUILayout.Toggle(inSumSelect, "");
								if (inSumSelect != newInSumSelect)
								{
									if (newInSumSelect)
									{
										list.AddToSumSelection(b);
									}
									else
									{
										list.RemoveFromSumSelection(b);
									}
								}
								
								Texture icon = AssetDatabase.GetCachedIcon(b.Name);
								if (GUILayout.Button(new GUIContent((n+1) + ". " + b.Name, icon), styleToUse, GUILayout.Height(LIST_HEIGHT)))
								{
									PingAssetInProject(b.Name);
								}
							GUILayout.EndHorizontal();
							
							useAlt = !useAlt;
						}
					GUILayout.EndVertical();

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

							string styleToUse = useAlt ? LIST_SMALL_ALT_STYLE_NAME : LIST_SMALL_STYLE_NAME;
							if (list.InSumSelection(b))
							{
								styleToUse = LIST_SMALL_SELECTED_NAME;
							}

							GUILayout.Label(b.Size, styleToUse, GUILayout.MinWidth(50), GUILayout.Height(LIST_HEIGHT));
							useAlt = !useAlt;
						}
					GUILayout.EndVertical();

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

							string styleToUse = useAlt ? LIST_SMALL_ALT_STYLE_NAME : LIST_SMALL_STYLE_NAME;
							if (list.InSumSelection(b))
							{
								styleToUse = LIST_SMALL_SELECTED_NAME;
							}

							string text = b.Percentage + "%";
							if (b.Percentage < 0)
							{
								text = NON_APPLICABLE_PERCENTAGE;
							}

							GUILayout.Label(text, styleToUse, GUILayout.MinWidth(30), GUILayout.Height(LIST_HEIGHT));
							useAlt = !useAlt;
						}
					GUILayout.EndVertical();
					GUILayout.EndHorizontal();
				}
			}
		}
	}
Exemplo n.º 2
0
        bool DrawColumn(int sta, int end, BuildReportTool.AssetList.SortType columnType, string columnName, bool showScrollbar, BuildReportTool.AssetList assetListCollection, BuildReportTool.SizePart[] assetList, ColumnDisplayDelegate dataToDisplay, ref Vector2 scollbarPos)
        {
            bool buttonPressed = false;
            GUILayout.BeginVertical();

            // ----------------------------------------------------------
            // column header
            string sortTypeStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_STYLE_NAME;
            if (assetListCollection.CurrentSortType == columnType)
            {
            if (assetListCollection.CurrentSortOrder == BuildReportTool.AssetList.SortOrder.Descending)
            {
                sortTypeStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_DESC_STYLE_NAME;
            }
            else
            {
                sortTypeStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_ASC_STYLE_NAME;
            }
            }
            if (GUILayout.Button(columnName, sortTypeStyleName, GUILayout.Height(LIST_HEIGHT)))
            {
            buttonPressed = true;
            }

            // ----------------------------------------------------------
            // scrollbar
            if (showScrollbar)
            {
            scollbarPos = GUILayout.BeginScrollView(scollbarPos,
                BuildReportTool.Window.Settings.HIDDEN_SCROLLBAR_STYLE_NAME, "verticalscrollbar");
            }
            else
            {
            scollbarPos = GUILayout.BeginScrollView(scollbarPos,
                BuildReportTool.Window.Settings.HIDDEN_SCROLLBAR_STYLE_NAME, BuildReportTool.Window.Settings.HIDDEN_SCROLLBAR_STYLE_NAME);
            }

            // ----------------------------------------------------------
            // actual contents
            bool useAlt = false;

            BuildReportTool.SizePart b;
            for (int n = sta; n < end; ++n)
            {
            b = assetList[n];

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

            GUILayout.Label(dataToDisplay(b), styleToUse, GUILayout.MinWidth(90), GUILayout.Height(LIST_HEIGHT));

            useAlt = !useAlt;
            }

            GUILayout.EndScrollView();

            GUILayout.EndVertical();

            return buttonPressed;
        }
    void InitiateDeleteSelectedInAssetList(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 = null;

        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.ReportManager.SegregateAssetSizesPerCategory(allWithRemoved, _buildInfo.FileFilters);

        listToDeleteFrom.Reinit(allWithRemoved, perCategoryOfList);
        listToDeleteFrom.ClearSelection();

        // print info about the delete operation to console
        string finalMessage = deletedCount + " file" + plural + " removed from your project.";
        if (deleteIsRecoverable)
        {
            finalMessage += " They can be recovered from your " + BuildReportTool.Util.NameOfOSTrashFolder + ".";
        }

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

        Debug.LogWarning(finalMessage);
    }
Exemplo n.º 4
0
        void DrawAssetList(Rect position, BuildReportTool.AssetList list, BuildReportTool.FileFilterGroup filter, int length)
        {
            if (list != null)
            {
            BuildReportTool.SizePart[] 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 (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)) )
                        {
                            list.ToggleSort(BuildReportTool.AssetList.SortType.AssetFullPath);
                        }

                        string sortTypeAssetFilenameStyleName = BuildReportTool.Window.Settings.LIST_COLUMN_HEADER_STYLE_NAME;
                        if (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)))
                        {
                            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"), 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   ", 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   ", true,
                            list, assetListToUse, (b) => {

                                string text = b.Percentage + "%";
                                if (b.Percentage < 0)
                                {
                                    text = Labels.NON_APPLICABLE_PERCENTAGE_LABEL;
                                }
                                return text;

                            }, ref _assetListScrollPos);
                    }

                    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();
                }
            }
            }
        }