From d33a729b5583b0f21d2ccaca293ae4d227232c82 Mon Sep 17 00:00:00 2001 From: r Star Date: Mon, 9 Jan 2023 23:29:49 +0800 Subject: [PATCH] add open and select option for ping type --- .../Editor/BookmarkEverythingEditor.cs | 1514 +++++++++-------- 1 file changed, 800 insertions(+), 714 deletions(-) diff --git a/BookmarkEverything/Assets/BookmarkEverything/Editor/BookmarkEverythingEditor.cs b/BookmarkEverything/Assets/BookmarkEverything/Editor/BookmarkEverythingEditor.cs index 549fa9c..e442419 100644 --- a/BookmarkEverything/Assets/BookmarkEverything/Editor/BookmarkEverythingEditor.cs +++ b/BookmarkEverything/Assets/BookmarkEverything/Editor/BookmarkEverythingEditor.cs @@ -1,118 +1,43 @@ -using System.Collections.Generic; +#region + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; using System.Linq; +using System.Reflection; +using System.Text; using UnityEditor; using UnityEngine; -using System.Text; +using Object = UnityEngine.Object; + +#endregion namespace BookmarkEverything { - public class BookmarkEverythingEditor : EditorWindow + public class BookmarkEverythingEditor : EditorWindow { - private SaveData _currentSettings = new SaveData(); + #region Private Variables - private bool _initialized; - private const char CHAR_SEPERATOR = ':'; - List _tempLocations = new List(); + private const char CHAR_SEPERATOR = ':'; private const string SETTINGS_FILENAME = "bookmarkeverythingsettings"; - private const string CATEGORY_SCENE = "Scenes"; - private const string CATEGORY_PREFAB = "Prefabs"; - private const string CATEGORY_SCRIPT = "Scripts"; - private const string CATEGORY_SO = "Scriptable Objects"; - private const string CATEGORY_STARRED = "Starred"; - private string[] _projectFinderHeaders = new string[] { CATEGORY_STARRED, CATEGORY_SCENE, CATEGORY_PREFAB, CATEGORY_SCRIPT, CATEGORY_SO }; - [System.Serializable] - public class EntryData - { - public string GUID; - public string Category; - public int Index; - - public EntryData(string path, string category, int index) - { - GUID = path; - Category = category; - Index = index; - } - public EntryData(string path) - { - GUID = path; - Category = "default"; - } - public EntryData(UnityEngine.Object obj) - { - //use GetAssetPath+AssetPathToGUID instead of TryGetGUIDAndLocalFileIdentifier because that method is fairly new and not supported in many unity editors - string path = AssetDatabase.GetAssetPath(obj); - string guid = AssetDatabase.AssetPathToGUID(path); - //AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out guid, out localId); - - GUID = guid; - if (obj.GetType() == typeof(DefaultAsset)) - { - Category = "Folder"; - } - else - { - string[] s = obj.name.Split(CHAR_SEPERATOR); - Category = s[s.Length - 1]; - } - } - public static EntryData Clone(EntryData data) - { - return new EntryData(data.GUID, data.Category, data.Index); - } - public static EntryData[] Clone(EntryData[] data) - { - EntryData[] newData = new EntryData[data.Length]; - for (int i = 0; i < data.Length; i++) - { - newData[i] = Clone(data[i]); - } - return newData; - } - - public static implicit operator EntryData(string path) - { - if (path == null) - { - return null; - } - return new EntryData(path); - } - public static implicit operator EntryData(UnityEngine.Object obj) - { - return new EntryData(obj); - } - - } - - [System.Serializable] - public class SaveData - { - public List EntryData = new List(); - public PingTypes PingType; - public bool VisualMode; - public bool AutoClose; - public bool ShowFullPath; - public bool ShowFullPathForFolders = true; - public SaveData(List entryData, PingTypes pingType, bool visualMode, bool autoClose, bool showFullPath, bool showFullPathForFolders) - { - EntryData = entryData; - PingType = pingType; - VisualMode = visualMode; - AutoClose = autoClose; - ShowFullPath = showFullPath; - ShowFullPathForFolders = showFullPathForFolders; - } - public SaveData() { } + private const string CATEGORY_SCENE = "Scenes"; + private const string CATEGORY_PREFAB = "Prefabs"; + private const string CATEGORY_SCRIPT = "Scripts"; + private const string CATEGORY_SO = "Scriptable Objects"; + private const string CATEGORY_STARRED = "Starred"; + + private const float _standardButtonMaxWidth = 25; + private const float _standardButtonMaxHeight = 18; + private const float _bigButtonMaxHeight = 30; + private SaveData _currentSettings = new SaveData(); + + private bool _initialized; + List _tempLocations = new List(); - public void Save() - { - IOHelper.ClearData(SETTINGS_FILENAME); - IOHelper.WriteToDisk(SETTINGS_FILENAME, this); - } - } + private string[] _projectFinderHeaders = + new string[] { CATEGORY_STARRED , CATEGORY_SCENE , CATEGORY_PREFAB , CATEGORY_SCRIPT , CATEGORY_SO }; - #region GUI REFERENCES GUIStyle _buttonStyle; GUIStyle _textFieldStyle; GUIStyle _scrollViewStyle; @@ -122,136 +47,69 @@ public void Save() GUIStyle _boldLabelStyle; Texture _editorWindowBackground; - #endregion - private List _headerContents = new List(); + private List _headerContents = new List(); private List _projectFinderContents = new List(); private PingTypes _pingType; - private bool _visualMode; - private bool _autoClose; - private bool _showFullPath; - private bool _showFullPathForFolder; + private bool _visualMode; + private bool _autoClose; + private bool _showFullPath; + private bool _showFullPathForFolder; - [MenuItem("Window/Bookmark Everything %h")] - private static void Init() - { - var windows = (BookmarkEverythingEditor[])Resources.FindObjectsOfTypeAll(typeof(BookmarkEverythingEditor)); - if (windows.Length == 0) - { - BookmarkEverythingEditor window = (BookmarkEverythingEditor)GetWindow(typeof(BookmarkEverythingEditor)); - window.InitInternal(); - + private int _tabIndex = 0; - } - else - { - FocusWindowIfItsOpen(typeof(BookmarkEverythingEditor)); - } - } + private int _projectFinderTabIndex = 0; + private bool _visualModeChanged; + private bool _controlVisualMode; + private bool _controlAutoClose; + private bool _autoCloseChanged; + private bool _controlShowFullPath; + private bool _showFullPathChanged; + private bool _controlShowFullPathForFolder; + private bool _showFullPathForFolderChanged; - private void OnEnable() { - titleContent =RetrieveGUIContent("Bookmark", "CustomSorting"); - _defaultGUIColor = GUI.color; - minSize = new Vector2(400,400); - } + private bool _reachedToAsset; + Vector2 _projectFinderEntriesScroll; + int _objectIndexToBeRemovedDueToDeletedAsset = -1; + int _objectIndexToBeRemoved = -1; - public void InitInternal() - { - //loads entries from playerprefs - //Construct main headers(Project Finder, Settings etc.) - LoadSettings(); - ConstructStyles(); - ConstructMainHeaders(); + Vector2 _settingScrollPos; + bool _changesMade = false; + int _lastlyAddedCount = -1; + Color _defaultGUIColor; - ConstructProjectFinderHeaders(); - _initialized = true; - //constructs all gui element styles + #endregion - } - /// - /// Construct tab view of Project Finder - /// - private void ConstructProjectFinderHeaders() - { - _projectFinderContents.Add(RetrieveGUIContent(CATEGORY_STARRED, "Favorite")); - _projectFinderContents.Add(RetrieveGUIContent(CATEGORY_SCENE, ResolveIconNameFromFileExtension("unity"))); - _projectFinderContents.Add(RetrieveGUIContent(CATEGORY_PREFAB, ResolveIconNameFromFileExtension("prefab"))); - _projectFinderContents.Add(RetrieveGUIContent(CATEGORY_SCRIPT, ResolveIconNameFromFileExtension("cs"))); - _projectFinderContents.Add(RetrieveGUIContent(CATEGORY_SO, ResolveIconNameFromFileExtension("asset"))); - if (_projectFinderContents.Count != _projectFinderHeaders.Length) - { - Debug.LogError("Inconsistency between Content count and Header count, please add to both of them!"); - } - } - private int GetIndexOfCategory(string category) + #region Unity events + + //Older versions of Unity doesn't like Close() being called in OnGUI + private void Update() { - for (int i = 0; i < _projectFinderHeaders.Length; i++) + if (_autoClose && _reachedToAsset) { - if (_projectFinderHeaders[i] == category) - { - return i; - } + this.Close(); } - return -1; - } - private string GetNameOfCategory(int index) - { - if (index >= 0 && index < _projectFinderHeaders.Length) + else if (!_autoClose && _reachedToAsset) { - return _projectFinderHeaders[index]; + _reachedToAsset = false; } - Debug.LogError("No category found with given index of " + index); - return ""; } - /// - /// Construct main tab view that is going to be used in - /// - private void ConstructMainHeaders() - { - _headerContents.Add(RetrieveGUIContent("Project Finder", "UnityEditor.SceneHierarchyWindow")); - _headerContents.Add(RetrieveGUIContent("Settings", "SettingsIcon")); - } + #endregion - private void OnGUI() - { - if (!_initialized) - { - InitInternal(); - } - if (_visualMode) - { - GUI.DrawTexture(new Rect(0, 0, EditorGUIUtility.currentViewWidth, position.height), _editorWindowBackground); - } - DrawHeader(); + #region Public Methods - DropAreaGUI(); - - } - //Older versions of Unity doesn't like Close() being called in OnGUI - private void Update() - { - if (_autoClose && _reachedToAsset) - { - this.Close(); - } - else if (!_autoClose && _reachedToAsset) - { - _reachedToAsset = false; - } - } - public void DropAreaGUI() + public void DropAreaGUI() { - Event evt = Event.current; - Rect drop_area = new Rect(0, 0, EditorGUIUtility.currentViewWidth, position.height); + Event evt = Event.current; + Rect drop_area = new Rect(0 , 0 , EditorGUIUtility.currentViewWidth , position.height); switch (evt.type) { - case EventType.DragUpdated: - case EventType.DragPerform: - if (!drop_area.Contains(evt.mousePosition)) - return; + case EventType.DragUpdated : + case EventType.DragPerform : + if (!drop_area.Contains(evt.mousePosition)) return; DragAndDrop.visualMode = DragAndDropVisualMode.Generic; @@ -259,16 +117,19 @@ public void DropAreaGUI() { DragAndDrop.AcceptDrag(); List duplicateList = new List(); - List allowedList = new List(); - foreach (UnityEngine.Object draggedObject in DragAndDrop.objectReferences) + List allowedList = new List(); + foreach (Object draggedObject in DragAndDrop.objectReferences) { - if(!AssetDatabase.Contains(draggedObject)) + if (!AssetDatabase.Contains(draggedObject)) { - EditorUtility.DisplayDialog("Bookmark Everything", "Objects from hierarchy is not supported for now. Would you like me to add that? Please e-mail me at dogukanerkut@gmail.com.", "Okay"); + EditorUtility.DisplayDialog("Bookmark Everything" , + "Objects from hierarchy is not supported for now. Would you like me to add that? Please e-mail me at dogukanerkut@gmail.com." , + "Okay"); return; } + EntryData entryData = new EntryData(draggedObject); - if (_tempLocations.Contains(entryData, new EntryDataGUIDComparer())) + if (_tempLocations.Contains(entryData , new EntryDataGUIDComparer())) { duplicateList.Add(_tempLocations.Find((entry) => entry.GUID == entryData.GUID)); } @@ -277,33 +138,39 @@ public void DropAreaGUI() allowedList.Add(entryData); } } - if(duplicateList.Count > 0) + + if (duplicateList.Count > 0) { StringBuilder sb = new StringBuilder(); sb.Append("\n\n"); - for (int i = 0; i < duplicateList.Count; i++) + for (int i = 0 ; i < duplicateList.Count ; i++) { - sb.Append(string.Format("{0} in {1} Category\n\n", GetNameForFile(AssetDatabase.GUIDToAssetPath(duplicateList[i].GUID)), duplicateList[i].Category)); + sb.Append(string.Format("{0} in {1} Category\n\n" , + GetNameForFile(AssetDatabase.GUIDToAssetPath(duplicateList[i].GUID)) , + duplicateList[i].Category)); } - if (EditorUtility.DisplayDialog("Bookmark Everything", string.Format("Duplicate Entries Found: {0} Would you still like to add them ?(Non-duplicates will be added anyway)", sb.ToString()), "Yes", "No")) + if (EditorUtility.DisplayDialog("Bookmark Everything" , + string.Format( + "Duplicate Entries Found: {0} Would you still like to add them ?(Non-duplicates will be added anyway)" , + sb.ToString()) , "Yes" , "No")) { duplicateList.AddRange(allowedList); - for (int i = 0; i < duplicateList.Count; i++) + for (int i = 0 ; i < duplicateList.Count ; i++) { if (_tabIndex == 0) { duplicateList[i].Category = GetNameOfCategory(_projectFinderTabIndex); - duplicateList[i].Index = _projectFinderTabIndex; + duplicateList[i].Index = _projectFinderTabIndex; } else if (_tabIndex == 1) { duplicateList[i].Category = GetNameOfCategory(0); - duplicateList[i].Index = 0; + duplicateList[i].Index = 0; _lastlyAddedCount++; - } } + _tempLocations.AddRange(duplicateList); if (_tabIndex == 0) { @@ -316,20 +183,21 @@ public void DropAreaGUI() } else { - for (int i = 0; i < allowedList.Count; i++) + for (int i = 0 ; i < allowedList.Count ; i++) { if (_tabIndex == 0) { allowedList[i].Category = GetNameOfCategory(_projectFinderTabIndex); - allowedList[i].Index = _projectFinderTabIndex; + allowedList[i].Index = _projectFinderTabIndex; } else if (_tabIndex == 1) { allowedList[i].Category = GetNameOfCategory(0); - allowedList[i].Index = 0; + allowedList[i].Index = 0; _lastlyAddedCount++; } } + _tempLocations.AddRange(allowedList); if (_tabIndex == 0) { @@ -341,21 +209,20 @@ public void DropAreaGUI() // } } } - else if(allowedList.Count > 0) + else if (allowedList.Count > 0) { - for (int i = 0; i < allowedList.Count; i++) + for (int i = 0 ; i < allowedList.Count ; i++) { if (_tabIndex == 0) { allowedList[i].Category = GetNameOfCategory(_projectFinderTabIndex); - allowedList[i].Index = _projectFinderTabIndex; + allowedList[i].Index = _projectFinderTabIndex; } else if (_tabIndex == 1) { allowedList[i].Category = GetNameOfCategory(0); - allowedList[i].Index = 0; + allowedList[i].Index = 0; _lastlyAddedCount++; - } } @@ -369,70 +236,70 @@ public void DropAreaGUI() // _changesMade = true; // } } - } + break; } } - #region HELPERS - - #region LOAD DATA - - private void LoadSettings() + public void InitInternal() { - //attempt to load the entries - _currentSettings = IOHelper.ReadFromDisk(SETTINGS_FILENAME); - //if nothing is saved, retrieve the default values - if (_currentSettings == null) - { - _currentSettings = new SaveData(); - _currentSettings.PingType = PingTypes.Both; - _currentSettings.Save(); - } - _tempLocations.AddRange(EntryData.Clone(_currentSettings.EntryData.ToArray())); + //loads entries from playerprefs + //Construct main headers(Project Finder, Settings etc.) + LoadSettings(); + ConstructStyles(); + ConstructMainHeaders(); - _pingType = _currentSettings.PingType; - _visualMode = _currentSettings.VisualMode; - VisualMode(_visualMode); - _autoClose = _currentSettings.AutoClose; - _showFullPath = _currentSettings.ShowFullPath; - _showFullPathForFolder = _currentSettings.ShowFullPathForFolders; + ConstructProjectFinderHeaders(); + _initialized = true; + //constructs all gui element styles } - #endregion + #endregion - #region STRING HELPERS + #region Private Methods private string Capital(string s) { - return System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s); + return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s); } - private string GetNameForFile(string path) + + /// + /// Construct main tab view that is going to be used in + /// + private void ConstructMainHeaders() { - if (_currentSettings.ShowFullPath) - { - return path; - } - string[] s = path.Split('/'); - return s[s.Length - 1]; + _headerContents.Add(RetrieveGUIContent("Project Finder" , "UnityEditor.SceneHierarchyWindow")); + _headerContents.Add(RetrieveGUIContent("Settings" , "SettingsIcon")); } - private string GetNameForFolder(string path) + + /// + /// Construct tab view of Project Finder + /// + private void ConstructProjectFinderHeaders() { - if (_currentSettings.ShowFullPathForFolders) + _projectFinderContents.Add(RetrieveGUIContent(CATEGORY_STARRED , "Favorite")); + _projectFinderContents.Add(RetrieveGUIContent(CATEGORY_SCENE , ResolveIconNameFromFileExtension("unity"))); + _projectFinderContents.Add(RetrieveGUIContent(CATEGORY_PREFAB , ResolveIconNameFromFileExtension("prefab"))); + _projectFinderContents.Add(RetrieveGUIContent(CATEGORY_SCRIPT , ResolveIconNameFromFileExtension("cs"))); + _projectFinderContents.Add(RetrieveGUIContent(CATEGORY_SO , ResolveIconNameFromFileExtension("asset"))); + if (_projectFinderContents.Count != _projectFinderHeaders.Length) { - return path; + Debug.LogError("Inconsistency between Content count and Header count, please add to both of them!"); } - string[] s = path.Split('/'); - return s[s.Length - 1]; } - private GUIContent ContentWithIcon(string name, string path) + private void ConstructStyles() { + VisualMode(_visualMode); + } - GUIContent c = new GUIContent(name, AssetDatabase.GetCachedIcon(path)); + private GUIContent ContentWithIcon(string name , string path) + { + GUIContent c = new GUIContent(name , AssetDatabase.GetCachedIcon(path)); return c; } + /// /// Assumes that the name is actually type and tries to resolve icon from name. /// @@ -444,85 +311,7 @@ private GUIContent ContentWithIcon(string name) c.text = name; return c; } - private string ResolveFileExtensionFromHeaderName(string header) - { - switch (header) - { - case CATEGORY_SCENE: - return "unity"; - case CATEGORY_PREFAB: - return "prefab"; - case CATEGORY_SCRIPT: - return "cs"; - case CATEGORY_SO: - return "asset"; - case CATEGORY_STARRED: - return "Favorite"; - default: - return "default"; - } - } - private string ResolveIconNameFromFileExtension(string fileExtension) - { - switch (fileExtension) - { - case "unity": - return "SceneAsset Icon"; - case "prefab": -#if UNITY_2018_3_OR_NEWER - return "d_Prefab Icon"; - #else - return "PrefabNormal Icon"; -#endif - case "mat": - return "Material Icon"; - case "cs": - return "cs Script Icon"; - case "wav": - return "AudioClip Icon"; - case "mp3": - return "AudioClip Icon"; - case "flac": - return "AudioClip Icon"; - case "folder": - return "Folder Icon"; - case "dll": - return "dll Script Icon"; - case "fbx": - return "PrefabModel Icon"; - case "asset": - return "ScriptableObject Icon"; - case "txt": - return "TextAsset Icon"; - case "controller": - return "UnityEditor.Graphs.AnimatorControllerTool"; - case "Favorite": - return "Favorite"; - - default: - return "DefaultAsset Icon"; - } - } - #endregion - - #region GUI STYLE ARRRANGEMENT - /// - /// Creates a single pixel Texture2D and paints it with given color. We can't directly edit GUIStyle's color so we do this. - /// - private Texture2D CreateColorForEditor(string htmlString) - { - Texture2D t = new Texture2D(1, 1); - Color c; -#if UNITY_5_1 - Color.TryParseHexString(htmlString, out c); -#else - ColorUtility.TryParseHtmlString(htmlString, out c); -#endif - t.SetPixel(0, 0, c); - t.Apply(); - return t; - } /// /// Creates a color from given HTML string. /// @@ -531,125 +320,37 @@ private Texture2D CreateColorForEditor(string htmlString) private Color CreateColor(string htmlString) { Color c; -#if UNITY_5_1 + #if UNITY_5_1 Color.TryParseHexString(htmlString, out c); -#else - ColorUtility.TryParseHtmlString(htmlString, out c); -#endif - return c; + #else + ColorUtility.TryParseHtmlString(htmlString , out c); + #endif + return c; } - private void ConstructStyles() + /// + /// Creates a single pixel Texture2D and paints it with given color. We can't directly edit GUIStyle's color so we do this. + /// + private Texture2D CreateColorForEditor(string htmlString) { - - VisualMode(_visualMode); - + Texture2D t = new Texture2D(1 , 1); + Color c; + #if UNITY_5_1 + Color.TryParseHexString(htmlString, out c); + #else + ColorUtility.TryParseHtmlString(htmlString , out c); + #endif + t.SetPixel(0 , 0 , c); + t.Apply(); + return t; } - private void VisualMode(bool visualMode) + private bool DrawButton(string name , string iconName = "" , string tooltip = "") { - _boldLabelStyle = new GUIStyle(EditorStyles.boldLabel); - - if (visualMode) + if (iconName != null && iconName != "") { - _buttonStyle = new GUIStyle(EditorStyles.miniButton); - _textFieldStyle = new GUIStyle(EditorStyles.textField); - _scrollViewStyle = new GUIStyle(); - _boxStyle = new GUIStyle(EditorStyles.helpBox); - _popupStyle = new GUIStyle(EditorStyles.popup); - _toolbarButtonStyle = new GUIStyle(EditorStyles.toolbarButton); - - _editorWindowBackground = CreateColorForEditor("#362914"); - - _buttonStyle.normal.background = CreateColorForEditor("#EACA93"); - _buttonStyle.active.background = CreateColorForEditor("#5A4B31"); - _buttonStyle.active.textColor = CreateColor("#ecf0f1"); - _buttonStyle.focused.background = CreateColorForEditor("#EACA93"); - _buttonStyle.alignment = TextAnchor.MiddleLeft; - - _scrollViewStyle.normal.background = CreateColorForEditor("#231703"); - - _textFieldStyle.normal.background = CreateColorForEditor("#EACA93"); - _textFieldStyle.active.background = CreateColorForEditor("#EACA93"); - _textFieldStyle.focused.background = CreateColorForEditor("#EACA93"); - - _boxStyle.normal.background = CreateColorForEditor("#EACA93"); - - _popupStyle.normal.background = CreateColorForEditor("#EACA93"); - _popupStyle.focused.background = CreateColorForEditor("#EACA93"); - - _toolbarButtonStyle.normal.background = CreateColorForEditor("#EACA93"); - _toolbarButtonStyle.alignment = TextAnchor.MiddleLeft; - } - else - { - _buttonStyle = new GUIStyle(EditorStyles.miniButton); - _textFieldStyle = new GUIStyle(EditorStyles.textField); - _scrollViewStyle = new GUIStyle(); - _boxStyle = new GUIStyle(EditorStyles.helpBox); - _popupStyle = new GUIStyle(EditorStyles.popup); - _toolbarButtonStyle = new GUIStyle(EditorStyles.toolbarButton); - - _buttonStyle.alignment = TextAnchor.MiddleLeft; - _toolbarButtonStyle.alignment = TextAnchor.MiddleLeft; - } - } -#endregion - - - -#endregion - - -#region ELEMENT DRAWERS - -#region GUICONTENT - - private GUIContent[] RetrieveGUIContent(string[] entries) - { - GUIContent[] c = new GUIContent[entries.Length]; - for (int i = 0; i < entries.Length; i++) - { - c[i] = RetrieveGUIContent(entries[i], ResolveIconNameFromFileExtension(ResolveFileExtensionFromHeaderName(entries[i]))); - } - return c; - } - - /// - /// Easily create GUIContent - /// - /// - /// - /// - /// - private GUIContent RetrieveGUIContent(string name, string iconName = "", string tooltip = "", bool useIconResolver = false) - { - if (iconName != null || iconName != "") - { - GUIContent c = new GUIContent(EditorGUIUtility.IconContent(iconName)); - c.text = name; - c.tooltip = tooltip; - return c; - } - else - { - return new GUIContent(name); - } - } -#endregion - -#region BUTTON - - private const float _standardButtonMaxWidth = 25; - private const float _standardButtonMaxHeight = 18; - private const float _bigButtonMaxHeight = 30; - private bool DrawButton(string name, string iconName = "", string tooltip = "") - { - if (iconName != null && iconName != "") - { - GUIContent c = new GUIContent(EditorGUIUtility.IconContent(iconName)); - c.text = name; + c.text = name; c.tooltip = tooltip; return GUILayout.Button(c); } @@ -657,175 +358,275 @@ private bool DrawButton(string name, string iconName = "", string tooltip = "") { return GUILayout.Button(name); } - } - private bool DrawButton(string name, string iconName = "", params GUILayoutOption[] options) + + private bool DrawButton(string name , string iconName = "" , params GUILayoutOption[] options) { if (iconName != null && iconName != "") { - GUIContent c = new GUIContent(EditorGUIUtility.IconContent(iconName)); c.text = name; - return GUILayout.Button(c, options); + return GUILayout.Button(c , options); } else { - return GUILayout.Button(name, options); + return GUILayout.Button(name , options); } - } - private bool DrawButton(string name, string iconName, ButtonTypes type) + + private bool DrawButton(string name , string iconName , ButtonTypes type) { GUILayoutOption[] options = null; switch (type) { - case ButtonTypes.Standard: + case ButtonTypes.Standard : options = new GUILayoutOption[] { GUILayout.MaxHeight(_standardButtonMaxHeight) }; break; - case ButtonTypes.Big: + case ButtonTypes.Big : options = new GUILayoutOption[] { GUILayout.MaxHeight(_bigButtonMaxHeight) }; break; - case ButtonTypes.SmallLongHeight: - options = new GUILayoutOption[]{ GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight + (EditorGUIUtility.singleLineHeight * .5f)), GUILayout.MaxWidth(25) }; - break; - case ButtonTypes.SmallNormalHeight: - options = new GUILayoutOption[] { GUILayout.MaxHeight(_standardButtonMaxHeight), GUILayout.MaxWidth(25) }; + case ButtonTypes.SmallLongHeight : + options = new GUILayoutOption[] + { + GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight + (EditorGUIUtility.singleLineHeight * .5f)) , + GUILayout.MaxWidth(25) + }; break; - default: + case ButtonTypes.SmallNormalHeight : + options = new GUILayoutOption[] { GUILayout.MaxHeight(_standardButtonMaxHeight) , GUILayout.MaxWidth(25) }; break; + default : break; } if (iconName != null && iconName != "") { - GUIContent c = new GUIContent(EditorGUIUtility.IconContent(iconName)); c.text = name; - return GUILayout.Button(c, _buttonStyle, options); + return GUILayout.Button(c , _buttonStyle , options); } else { - return GUILayout.Button(name, options); + return GUILayout.Button(name , options); } + } + private void DrawHeader() + { + _tabIndex = GUILayout.Toolbar(_tabIndex , _headerContents.ToArray()); + if (_tabIndex == 0 && _changesMade) + { + bool save = EditorUtility.DisplayDialog("Bookmark Everything" , + "You have unsaved changes. Would you like to save them?" , "Yes" , "No"); + if (save) + { + SaveChanges(); + } + else + { + _lastlyAddedCount = -1; + _tempLocations.Clear(); + _tempLocations.AddRange(EntryData.Clone(_currentSettings.EntryData.ToArray())); + _changesMade = false; + } + } + switch (_tabIndex) + { + case 0 : + DrawProjectFinder(); + break; + case 1 : + DrawSettings(); + break; + default : break; + } } -#endregion + private void DrawInnerSettings() + { + EditorGUILayout.BeginVertical(_boxStyle); + EditorGUILayout.LabelField("General Settings" , _boldLabelStyle); + EditorGUILayout.LabelField("" , GUI.skin.horizontalSlider); + EditorGUILayout.BeginHorizontal(); + string label = "Current Ping Type : "; + EditorGUILayout.LabelField(label , GUILayout.MaxWidth(label.Length * 7.3f)); + if (_pingType == PingTypes.Ping) + { + if (GUILayout.Button("Ping" , _buttonStyle , GUILayout.ExpandWidth(false))) + { + _pingType = PingTypes.Selection; + _currentSettings.PingType = _pingType; + _currentSettings.Save(); + } + } + else if (_pingType == PingTypes.Selection) + { + if (GUILayout.Button("Selection" , _buttonStyle , GUILayout.ExpandWidth(false))) + { + _pingType = PingTypes.Both; + _currentSettings.PingType = _pingType; + _currentSettings.Save(); + } + } + else if (_pingType == PingTypes.Both) + { + if (GUILayout.Button("Both" , _buttonStyle , GUILayout.ExpandWidth(false))) + { + _pingType = PingTypes.OpenAndSelect; + _currentSettings.PingType = _pingType; + _currentSettings.Save(); + } + } + else if (_pingType == PingTypes.OpenAndSelect) + { + if (GUILayout.Button("Open And Select" , _buttonStyle , GUILayout.ExpandWidth(false))) + { + _pingType = PingTypes.Ping; + _currentSettings.PingType = _pingType; + _currentSettings.Save(); + } + } -#region READ-ONLY TEXT FIELD + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + _controlAutoClose = _autoClose; + _autoClose = EditorGUILayout.Toggle("Auto Close : " , _autoClose); + + if (_controlAutoClose != _autoClose) + { + _autoCloseChanged = true; + } + + if (_autoCloseChanged) + { + _currentSettings.AutoClose = _autoClose; + _currentSettings.Save(); + _autoCloseChanged = false; + } + + EditorGUILayout.EndHorizontal(); - void ReadOnlyTextField(string label, string text) - { EditorGUILayout.BeginHorizontal(); + label = "Show Full Path : "; + _controlShowFullPath = _showFullPath; + _showFullPath = EditorGUILayout.Toggle(label , _showFullPath); + + if (_controlShowFullPath != _showFullPath) + { + _showFullPathChanged = true; + } + + if (_showFullPathChanged) { - EditorGUILayout.LabelField(label, GUILayout.Width(EditorGUIUtility.labelWidth - 4)); - EditorGUILayout.SelectableLabel(text, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight)); + _currentSettings.ShowFullPath = _showFullPath; + _currentSettings.Save(); + _showFullPathChanged = false; } + EditorGUILayout.EndHorizontal(); - } -#endregion + EditorGUILayout.BeginHorizontal(); + label = "Show Full Path(Folders) : "; + _controlShowFullPathForFolder = _showFullPathForFolder; + _showFullPathForFolder = EditorGUILayout.Toggle(label , _showFullPathForFolder); -#endregion + if (_controlShowFullPathForFolder != _showFullPathForFolder) + { + _showFullPathForFolderChanged = true; + } -#region CONTENT + if (_showFullPathForFolderChanged) + { + _currentSettings.ShowFullPathForFolders = _showFullPathForFolder; + _currentSettings.Save(); + _showFullPathForFolderChanged = false; + } -#region MAIN HEADER DRAWERS + EditorGUILayout.EndHorizontal(); - private int _tabIndex = 0; - private void DrawHeader() - { - _tabIndex = GUILayout.Toolbar(_tabIndex, _headerContents.ToArray()); - if (_tabIndex == 0 && _changesMade) + EditorGUILayout.BeginHorizontal(); + + label = "Visual Mode(Experimental!) : "; + _controlVisualMode = _visualMode; + _visualMode = EditorGUILayout.Toggle(label , _visualMode); + + if (_controlVisualMode != _visualMode) { - bool save = EditorUtility.DisplayDialog("Bookmark Everything", "You have unsaved changes. Would you like to save them?", "Yes", "No"); - if (save) - { - SaveChanges(); - } - else - { - _lastlyAddedCount = -1; - _tempLocations.Clear(); - _tempLocations.AddRange(EntryData.Clone(_currentSettings.EntryData.ToArray())); - _changesMade = false; - } + _visualModeChanged = true; } - switch (_tabIndex) + + if (_visualModeChanged) { - case 0: - DrawProjectFinder(); - break; - case 1: - DrawSettings(); - break; - default: - break; + VisualMode(_visualMode); + _currentSettings.VisualMode = _visualMode; + _currentSettings.Save(); + _visualModeChanged = false; } + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.EndVertical(); } - private int _projectFinderTabIndex = 0; - private bool _visualModeChanged; - private bool _controlVisualMode; - private bool _controlAutoClose; - private bool _autoCloseChanged; - private bool _controlShowFullPath; - private bool _showFullPathChanged; - private bool _controlShowFullPathForFolder; - private bool _showFullPathForFolderChanged; + private void DrawProjectFinder() { - _projectFinderTabIndex = GUILayout.Toolbar(_projectFinderTabIndex, _projectFinderContents.ToArray(), _toolbarButtonStyle, GUILayout.ExpandHeight(false)); + _projectFinderTabIndex = GUILayout.Toolbar(_projectFinderTabIndex , _projectFinderContents.ToArray() , + _toolbarButtonStyle , GUILayout.ExpandHeight(false)); switch (_projectFinderTabIndex) { - case 0://starred + case 0 : //starred DrawProjectFinderEntries(CATEGORY_STARRED); break; - case 1://scenes + case 1 : //scenes DrawProjectFinderEntries(CATEGORY_SCENE); break; - case 2://prefab + case 2 : //prefab DrawProjectFinderEntries(CATEGORY_PREFAB); break; - case 3://script + case 3 : //script DrawProjectFinderEntries(CATEGORY_SCRIPT); break; - case 4://so + case 4 : //so DrawProjectFinderEntries(CATEGORY_SO); break; - default: - break; + default : break; } } - private bool _reachedToAsset; - Vector2 _projectFinderEntriesScroll; - int _objectIndexToBeRemovedDueToDeletedAsset = -1; - int _objectIndexToBeRemoved = -1; + private void DrawProjectFinderEntries(string category) { - bool clicked = false; - _projectFinderEntriesScroll = EditorGUILayout.BeginScrollView(_projectFinderEntriesScroll, _scrollViewStyle, GUILayout.MaxHeight(position.height)); - for (int i = 0; i < _currentSettings.EntryData.Count; i++) + bool clicked = false; + _projectFinderEntriesScroll = + EditorGUILayout.BeginScrollView(_projectFinderEntriesScroll , _scrollViewStyle , + GUILayout.MaxHeight(position.height)); + for (int i = 0 ; i < _currentSettings.EntryData.Count ; i++) { if (_currentSettings.EntryData[i].Category == category) { - string path = AssetDatabase.GUIDToAssetPath(_currentSettings.EntryData[i].GUID); - bool exists = IOHelper.Exists(path); - bool isFolder = IOHelper.IsFolder(path); + string path = AssetDatabase.GUIDToAssetPath(_currentSettings.EntryData[i].GUID); + bool exists = IOHelper.Exists(path); + bool isFolder = IOHelper.IsFolder(path); GUIContent content; if (exists) { - content = ContentWithIcon(isFolder ? GetNameForFolder(path) : GetNameForFile(path), path); + content = ContentWithIcon(isFolder ? GetNameForFolder(path) : GetNameForFile(path) , path); } else { - content = RetrieveGUIContent((isFolder ? GetNameForFolder(path) : GetNameForFile(path)) + "(File is removed, click to remove)" , "console.erroricon.sml"); + content = RetrieveGUIContent( + (isFolder ? GetNameForFolder(path) : GetNameForFile(path)) + "(File is removed, click to remove)" , + "console.erroricon.sml"); } - EditorGUILayout.BeginHorizontal(); - if (GUILayout.Button(content, _buttonStyle, GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight + (EditorGUIUtility.singleLineHeight * .5f)))) + + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button(content , _buttonStyle , + GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight + + (EditorGUIUtility.singleLineHeight * .5f)))) { if (exists) { @@ -835,6 +636,7 @@ private void DrawProjectFinderEntries(string category) { Selection.activeObject = null; } + EditorGUIUtility.PingObject(AssetDatabase.LoadMainAssetAtPath(path)); } else if (_pingType == PingTypes.Selection) @@ -843,90 +645,103 @@ private void DrawProjectFinderEntries(string category) } else if (_pingType == PingTypes.Both) { - if (Selection.activeObject) - { - Selection.activeObject = null; - } + if (Selection.activeObject) Selection.activeObject = null; EditorGUIUtility.PingObject(AssetDatabase.LoadMainAssetAtPath(path)); Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(path); } - clicked = true; + else if (_pingType == PingTypes.OpenAndSelect) + { + if (Selection.activeObject) Selection.activeObject = null; + if (Path.HasExtension(path)) Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(path); + else OpenDir(path); + } + + clicked = true; } else { _objectIndexToBeRemovedDueToDeletedAsset = i; } + _reachedToAsset = true; } - if (DrawButton("", "ol minus", ButtonTypes.SmallLongHeight)) + + if (DrawButton("" , "ol minus" , ButtonTypes.SmallLongHeight)) { _objectIndexToBeRemoved = i; } - EditorGUILayout.EndHorizontal(); - } + EditorGUILayout.EndHorizontal(); + } } + if (_objectIndexToBeRemovedDueToDeletedAsset != -1) { _tempLocations.RemoveAt(_objectIndexToBeRemovedDueToDeletedAsset); _objectIndexToBeRemovedDueToDeletedAsset = -1; SaveChanges(); } - if(_objectIndexToBeRemoved != -1) + + if (_objectIndexToBeRemoved != -1) { - _tempLocations.RemoveAt(_objectIndexToBeRemoved); + _tempLocations.RemoveAt(_objectIndexToBeRemoved); _objectIndexToBeRemoved = -1; SaveChanges(); } - if (_currentSettings.EntryData.Count == 0) + + if (_currentSettings.EntryData.Count == 0) { - EditorGUILayout.LabelField("You can Drag&Drop assets from Project Folder and easily access them here.", _boldLabelStyle); + EditorGUILayout.LabelField("You can Drag&Drop assets from Project Folder and easily access them here." , + _boldLabelStyle); } + EditorGUILayout.EndScrollView(); - - //Older version of unity has issues with FocusProjectWindow being in the middle of the run(before EndXViews). - if (clicked) - { - EditorUtility.FocusProjectWindow(); - } - } - Vector2 _settingScrollPos; - bool _changesMade = false; - int _lastlyAddedCount = -1; - Color _defaultGUIColor; + //Older version of unity has issues with FocusProjectWindow being in the middle of the run(before EndXViews). + if (clicked) + { + EditorUtility.FocusProjectWindow(); + } + } + private void DrawSettings() { DrawInnerSettings(); - int toBeRemoved = -1; - UnityEngine.Object pingedObject = null; - _settingScrollPos = EditorGUILayout.BeginScrollView(_settingScrollPos, _scrollViewStyle, GUILayout.MaxHeight(position.height)); + int toBeRemoved = -1; + Object pingedObject = null; + _settingScrollPos = + EditorGUILayout.BeginScrollView(_settingScrollPos , _scrollViewStyle , GUILayout.MaxHeight(position.height)); //Iterate all found entries - key is path value is type EditorGUILayout.BeginVertical(_boxStyle); - EditorGUILayout.LabelField("Manage Registered Assets", _boldLabelStyle); - EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); - for (int i = 0; i < _tempLocations.Count; i++) + EditorGUILayout.LabelField("Manage Registered Assets" , _boldLabelStyle); + EditorGUILayout.LabelField("" , GUI.skin.horizontalSlider); + for (int i = 0 ; i < _tempLocations.Count ; i++) { - bool exists = IOHelper.Exists(_tempLocations[i].GUID, ExistentialCheckStrategy.GUID); - if (_lastlyAddedCount != -1 && i >= _tempLocations.Count - _lastlyAddedCount -1) + bool exists = IOHelper.Exists(_tempLocations[i].GUID , ExistentialCheckStrategy.GUID); + if (_lastlyAddedCount != -1 && i >= _tempLocations.Count - _lastlyAddedCount - 1) { GUI.color = Color.green; } + EditorGUILayout.BeginHorizontal(); { EditorGUILayout.BeginVertical(); { - string fullPath = exists ? AssetDatabase.GUIDToAssetPath(_tempLocations[i].GUID) : "(Removed)" + AssetDatabase.GUIDToAssetPath(_tempLocations[i].GUID); + string fullPath = exists + ? AssetDatabase.GUIDToAssetPath(_tempLocations[i].GUID) + : "(Removed)" + AssetDatabase.GUIDToAssetPath(_tempLocations[i].GUID); GUILayout.Space(4); - EditorGUILayout.SelectableLabel(fullPath, _textFieldStyle, GUILayout.Height(EditorGUIUtility.singleLineHeight)); + EditorGUILayout.SelectableLabel(fullPath , _textFieldStyle , + GUILayout.Height(EditorGUIUtility.singleLineHeight)); } EditorGUILayout.EndVertical(); if (!exists) { GUI.enabled = false; } - if (DrawButton("", "ViewToolOrbit", ButtonTypes.SmallNormalHeight)) + + if (DrawButton("" , "ViewToolOrbit" , ButtonTypes.SmallNormalHeight)) { pingedObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(_tempLocations[i].GUID)); if (Selection.activeObject) @@ -935,18 +750,18 @@ private void DrawSettings() } if (_pingType == PingTypes.Ping) - { - EditorGUIUtility.PingObject(pingedObject); - } - else if (_pingType == PingTypes.Selection) - { - Selection.activeObject = pingedObject; - } - else if (_pingType == PingTypes.Both) - { - EditorGUIUtility.PingObject(pingedObject); - Selection.activeObject = pingedObject; - } + { + EditorGUIUtility.PingObject(pingedObject); + } + else if (_pingType == PingTypes.Selection) + { + Selection.activeObject = pingedObject; + } + else if (_pingType == PingTypes.Both) + { + EditorGUIUtility.PingObject(pingedObject); + Selection.activeObject = pingedObject; + } } // if (DrawButton("Assign Selected Object", "TimeLinePingPong", ButtonTypes.Standard)) @@ -965,21 +780,26 @@ private void DrawSettings() // } //çatecori ///*int categoryIndex*/ = GetIndexOfCategory(_tempPlayerPrefLocations[i].Category); - _tempLocations[i].Index = EditorGUILayout.Popup(_tempLocations[i].Index, RetrieveGUIContent(_projectFinderHeaders), _popupStyle, GUILayout.MinHeight(EditorGUIUtility.singleLineHeight), GUILayout.MaxWidth(150)); + _tempLocations[i].Index = EditorGUILayout.Popup(_tempLocations[i].Index , + RetrieveGUIContent(_projectFinderHeaders) , _popupStyle , + GUILayout.MinHeight(EditorGUIUtility.singleLineHeight) , + GUILayout.MaxWidth(150)); _tempLocations[i].Category = _projectFinderHeaders[_tempLocations[i].Index]; - + if (!exists) { GUI.enabled = true; } + //Remove Button - if (DrawButton("", "ol minus", ButtonTypes.SmallNormalHeight)) + if (DrawButton("" , "ol minus" , ButtonTypes.SmallNormalHeight)) { - if(_lastlyAddedCount != -1 && i >= _tempLocations.Count - _lastlyAddedCount -1) + if (_lastlyAddedCount != -1 && i >= _tempLocations.Count - _lastlyAddedCount - 1) { _lastlyAddedCount--; } + toBeRemoved = i; } } @@ -989,11 +809,13 @@ private void DrawSettings() { GUI.color = _defaultGUIColor; } - }//endfor - if (_tempLocations.Count == 0 && _currentSettings.EntryData.Count == 0) + } //endfor + + if (_tempLocations.Count == 0 && _currentSettings.EntryData.Count == 0) { - EditorGUILayout.LabelField("Start dragging some assets from Project Folder!", _boldLabelStyle); + EditorGUILayout.LabelField("Start dragging some assets from Project Folder!" , _boldLabelStyle); } + EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); @@ -1002,6 +824,7 @@ private void DrawSettings() { EditorUtility.FocusProjectWindow(); } + //Remove item if (toBeRemoved != -1) { @@ -1024,7 +847,7 @@ private void DrawSettings() // } //Save - + //detect if any change occured, if not reverse the HelpBox if (_currentSettings.EntryData.Count != _tempLocations.Count) { @@ -1032,185 +855,448 @@ private void DrawSettings() } else { - for (int i = 0; i < _currentSettings.EntryData.Count; i++) + for (int i = 0 ; i < _currentSettings.EntryData.Count ; i++) { - if (_currentSettings.EntryData[i].GUID != _tempLocations[i].GUID || _currentSettings.EntryData[i].Category != _tempLocations[i].Category) + if (_currentSettings.EntryData[i].GUID != _tempLocations[i].GUID + || _currentSettings.EntryData[i].Category != _tempLocations[i].Category) { _changesMade = true; break; } + if (i == _currentSettings.EntryData.Count - 1) { _changesMade = false; } } } + //Show info about saving if (_changesMade) { - if (DrawButton("Save", "redLight", ButtonTypes.Big)) + if (DrawButton("Save" , "redLight" , ButtonTypes.Big)) { SaveChanges(); } - EditorGUILayout.HelpBox("Changes are made, you should save changes if you want to keep them.", MessageType.Info); - if (DrawButton("Discard Changes", "", ButtonTypes.Standard)) + + EditorGUILayout.HelpBox("Changes are made, you should save changes if you want to keep them." , MessageType.Info); + if (DrawButton("Discard Changes" , "" , ButtonTypes.Standard)) { _lastlyAddedCount = -1; _tempLocations.Clear(); _tempLocations.AddRange(EntryData.Clone(_currentSettings.EntryData.ToArray())); - _changesMade = false; + _changesMade = false; } - } - } - private void SaveChanges() + private int GetIndexOfCategory(string category) { - _currentSettings.EntryData.Clear(); - _currentSettings.EntryData.AddRange(EntryData.Clone(_tempLocations.ToArray())); - _lastlyAddedCount = -1; + for (int i = 0 ; i < _projectFinderHeaders.Length ; i++) + { + if (_projectFinderHeaders[i] == category) + { + return i; + } + } - _currentSettings.Save(); - _changesMade = false; + return -1; } -#endregion - -#endregion - private void DrawInnerSettings() + private string GetNameForFile(string path) { - EditorGUILayout.BeginVertical(_boxStyle); - EditorGUILayout.LabelField("General Settings", _boldLabelStyle); - EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); - EditorGUILayout.BeginHorizontal(); - string label = "Current Ping Type : "; - EditorGUILayout.LabelField(label, GUILayout.MaxWidth(label.Length * 7.3f)); - if (_pingType == PingTypes.Ping) - { - if (GUILayout.Button("Ping", _buttonStyle, GUILayout.ExpandWidth(false))) - { - _pingType = PingTypes.Selection; - _currentSettings.PingType = _pingType; - _currentSettings.Save(); - } - } - else if (_pingType == PingTypes.Selection) - { - if (GUILayout.Button("Selection", _buttonStyle, GUILayout.ExpandWidth(false))) - { - _pingType = PingTypes.Both; - _currentSettings.PingType = _pingType; - _currentSettings.Save(); - } - } - else if (_pingType == PingTypes.Both) - { - if (GUILayout.Button("Both", _buttonStyle, GUILayout.ExpandWidth(false))) - { - _pingType = PingTypes.Ping; - _currentSettings.PingType = _pingType; - _currentSettings.Save(); - } - } - EditorGUILayout.EndHorizontal(); + if (_currentSettings.ShowFullPath) + { + return path; + } - EditorGUILayout.BeginHorizontal(); - _controlAutoClose = _autoClose; - _autoClose = EditorGUILayout.Toggle("Auto Close : ", _autoClose); + string[] s = path.Split('/'); + return s[s.Length - 1]; + } - if (_controlAutoClose != _autoClose) - { - _autoCloseChanged = true; - } - if (_autoCloseChanged) - { - _currentSettings.AutoClose = _autoClose; - _currentSettings.Save(); - _autoCloseChanged = false; - } - EditorGUILayout.EndHorizontal(); + private string GetNameForFolder(string path) + { + if (_currentSettings.ShowFullPathForFolders) + { + return path; + } + string[] s = path.Split('/'); + return s[s.Length - 1]; + } + private string GetNameOfCategory(int index) + { + if (index >= 0 && index < _projectFinderHeaders.Length) + { + return _projectFinderHeaders[index]; + } - EditorGUILayout.BeginHorizontal(); - label = "Show Full Path : "; - _controlShowFullPath = _showFullPath; - _showFullPath = EditorGUILayout.Toggle(label, _showFullPath); + Debug.LogError("No category found with given index of " + index); + return ""; + } - if (_controlShowFullPath != _showFullPath) - { - _showFullPathChanged = true; - } - if (_showFullPathChanged) - { - _currentSettings.ShowFullPath = _showFullPath; - _currentSettings.Save(); - _showFullPathChanged = false; - } - - EditorGUILayout.EndHorizontal(); + [MenuItem("Window/Bookmark Everything %h")] + private static void Init() + { + var windows = (BookmarkEverythingEditor[])Resources.FindObjectsOfTypeAll(typeof(BookmarkEverythingEditor)); + if (windows.Length == 0) + { + BookmarkEverythingEditor window = (BookmarkEverythingEditor)GetWindow(typeof(BookmarkEverythingEditor)); + window.InitInternal(); + } + else + { + FocusWindowIfItsOpen(typeof(BookmarkEverythingEditor)); + } + } - EditorGUILayout.BeginHorizontal(); - label = "Show Full Path(Folders) : "; - _controlShowFullPathForFolder = _showFullPathForFolder; - _showFullPathForFolder = EditorGUILayout.Toggle(label, _showFullPathForFolder); + private void LoadSettings() + { + //attempt to load the entries + _currentSettings = IOHelper.ReadFromDisk(SETTINGS_FILENAME); + //if nothing is saved, retrieve the default values + if (_currentSettings == null) + { + _currentSettings = new SaveData(); + _currentSettings.PingType = PingTypes.Both; + _currentSettings.Save(); + } + + _tempLocations.AddRange(EntryData.Clone(_currentSettings.EntryData.ToArray())); + + _pingType = _currentSettings.PingType; + _visualMode = _currentSettings.VisualMode; + VisualMode(_visualMode); + _autoClose = _currentSettings.AutoClose; + _showFullPath = _currentSettings.ShowFullPath; + _showFullPathForFolder = _currentSettings.ShowFullPathForFolders; + } + + private void OnEnable() + { + titleContent = RetrieveGUIContent("Bookmark" , "CustomSorting"); + _defaultGUIColor = GUI.color; + minSize = new Vector2(400 , 400); + } + + private void OnGUI() + { + if (!_initialized) + { + InitInternal(); + } + + if (_visualMode) + { + GUI.DrawTexture(new Rect(0 , 0 , EditorGUIUtility.currentViewWidth , position.height) , _editorWindowBackground); + } + + DrawHeader(); + + DropAreaGUI(); + } + + private static void OpenDir(string path) + { + var asset = AssetDatabase.LoadMainAssetAtPath(path); + var pt = Type.GetType("UnityEditor.ProjectBrowser,UnityEditor"); + var ins = pt.GetField("s_LastInteractedProjectBrowser" , BindingFlags.Static | BindingFlags.Public).GetValue(null); + var showDirMeth = pt.GetMethod("ShowFolderContents" , BindingFlags.NonPublic | BindingFlags.Instance); + showDirMeth.Invoke(ins , new object[] { asset.GetInstanceID() , true }); + } + + void ReadOnlyTextField(string label , string text) + { + EditorGUILayout.BeginHorizontal(); + { + EditorGUILayout.LabelField(label , GUILayout.Width(EditorGUIUtility.labelWidth - 4)); + EditorGUILayout.SelectableLabel(text , EditorStyles.textField , GUILayout.Height(EditorGUIUtility.singleLineHeight)); + } + EditorGUILayout.EndHorizontal(); + } + + private string ResolveFileExtensionFromHeaderName(string header) + { + switch (header) + { + case CATEGORY_SCENE : return "unity"; + case CATEGORY_PREFAB : return "prefab"; + case CATEGORY_SCRIPT : return "cs"; + case CATEGORY_SO : return "asset"; + case CATEGORY_STARRED : return "Favorite"; + default : return "default"; + } + } + + private string ResolveIconNameFromFileExtension(string fileExtension) + { + switch (fileExtension) + { + case "unity" : return "SceneAsset Icon"; + case "prefab" : return "d_Prefab Icon"; + case "mat" : return "Material Icon"; + case "cs" : return "cs Script Icon"; + case "wav" : return "AudioClip Icon"; + case "mp3" : return "AudioClip Icon"; + case "flac" : return "AudioClip Icon"; + case "folder" : return "Folder Icon"; + case "dll" : return "dll Script Icon"; + case "fbx" : return "PrefabModel Icon"; + case "asset" : return "ScriptableObject Icon"; + case "txt" : return "TextAsset Icon"; + case "controller" : return "UnityEditor.Graphs.AnimatorControllerTool"; + case "Favorite" : return "Favorite"; + + default : return "DefaultAsset Icon"; + } + } + + private GUIContent[] RetrieveGUIContent(string[] entries) + { + GUIContent[] c = new GUIContent[entries.Length]; + for (int i = 0 ; i < entries.Length ; i++) + { + c[i] = RetrieveGUIContent( + entries[i] , ResolveIconNameFromFileExtension(ResolveFileExtensionFromHeaderName(entries[i]))); + } + + return c; + } + + /// + /// Easily create GUIContent + /// + /// + /// + /// + /// + private GUIContent RetrieveGUIContent(string name , string iconName = "" , string tooltip = "" , bool useIconResolver = false) + { + if (iconName != null || iconName != "") + { + GUIContent c = new GUIContent(EditorGUIUtility.IconContent(iconName)); + c.text = name; + c.tooltip = tooltip; + return c; + } + else + { + return new GUIContent(name); + } + } + + private void SaveChanges() + { + _currentSettings.EntryData.Clear(); + _currentSettings.EntryData.AddRange(EntryData.Clone(_tempLocations.ToArray())); + _lastlyAddedCount = -1; + + _currentSettings.Save(); + _changesMade = false; + } + + private void VisualMode(bool visualMode) + { + _boldLabelStyle = new GUIStyle(EditorStyles.boldLabel); + + if (visualMode) + { + _buttonStyle = new GUIStyle(EditorStyles.miniButton); + _textFieldStyle = new GUIStyle(EditorStyles.textField); + _scrollViewStyle = new GUIStyle(); + _boxStyle = new GUIStyle(EditorStyles.helpBox); + _popupStyle = new GUIStyle(EditorStyles.popup); + _toolbarButtonStyle = new GUIStyle(EditorStyles.toolbarButton); + + _editorWindowBackground = CreateColorForEditor("#362914"); + + _buttonStyle.normal.background = CreateColorForEditor("#EACA93"); + _buttonStyle.active.background = CreateColorForEditor("#5A4B31"); + _buttonStyle.active.textColor = CreateColor("#ecf0f1"); + _buttonStyle.focused.background = CreateColorForEditor("#EACA93"); + _buttonStyle.alignment = TextAnchor.MiddleLeft; + + _scrollViewStyle.normal.background = CreateColorForEditor("#231703"); + + _textFieldStyle.normal.background = CreateColorForEditor("#EACA93"); + _textFieldStyle.active.background = CreateColorForEditor("#EACA93"); + _textFieldStyle.focused.background = CreateColorForEditor("#EACA93"); + + _boxStyle.normal.background = CreateColorForEditor("#EACA93"); + + _popupStyle.normal.background = CreateColorForEditor("#EACA93"); + _popupStyle.focused.background = CreateColorForEditor("#EACA93"); + + _toolbarButtonStyle.normal.background = CreateColorForEditor("#EACA93"); + _toolbarButtonStyle.alignment = TextAnchor.MiddleLeft; + } + else + { + _buttonStyle = new GUIStyle(EditorStyles.miniButton); + _textFieldStyle = new GUIStyle(EditorStyles.textField); + _scrollViewStyle = new GUIStyle(); + _boxStyle = new GUIStyle(EditorStyles.helpBox); + _popupStyle = new GUIStyle(EditorStyles.popup); + _toolbarButtonStyle = new GUIStyle(EditorStyles.toolbarButton); + + _buttonStyle.alignment = TextAnchor.MiddleLeft; + _toolbarButtonStyle.alignment = TextAnchor.MiddleLeft; + } + } + + #endregion + + #region Nested Types + + [Serializable] + public class EntryData + { + #region Public Variables + + public int Index; + public string Category; + public string GUID; + + #endregion + + #region Constructor + + public EntryData(string path , string category , int index) + { + GUID = path; + Category = category; + Index = index; + } + + public EntryData(string path) + { + GUID = path; + Category = "default"; + } - if (_controlShowFullPathForFolder != _showFullPathForFolder) + public EntryData(Object obj) + { + //use GetAssetPath+AssetPathToGUID instead of TryGetGUIDAndLocalFileIdentifier because that method is fairly new and not supported in many unity editors + string path = AssetDatabase.GetAssetPath(obj); + string guid = AssetDatabase.AssetPathToGUID(path); + //AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out guid, out localId); + + GUID = guid; + if (obj.GetType() == typeof(DefaultAsset)) { - _showFullPathForFolderChanged = true; + Category = "Folder"; } - if (_showFullPathForFolderChanged) + else { - _currentSettings.ShowFullPathForFolders = _showFullPathForFolder; - _currentSettings.Save(); - _showFullPathForFolderChanged = false; + string[] s = obj.name.Split(CHAR_SEPERATOR); + Category = s[s.Length - 1]; } + } - EditorGUILayout.EndHorizontal(); + #endregion - EditorGUILayout.BeginHorizontal(); + #region Public Methods - label = "Visual Mode(Experimental!) : "; - _controlVisualMode = _visualMode; - _visualMode = EditorGUILayout.Toggle(label, _visualMode); + public static EntryData Clone(EntryData data) + { + return new EntryData(data.GUID , data.Category , data.Index); + } - if (_controlVisualMode != _visualMode) + public static EntryData[] Clone(EntryData[] data) + { + EntryData[] newData = new EntryData[data.Length]; + for (int i = 0 ; i < data.Length ; i++) { - _visualModeChanged = true; + newData[i] = Clone(data[i]); } - if (_visualModeChanged) + + return newData; + } + + public static implicit operator EntryData(string path) + { + if (path == null) { - VisualMode(_visualMode); - _currentSettings.VisualMode = _visualMode; - _currentSettings.Save(); - _visualModeChanged = false; + return null; } - EditorGUILayout.EndHorizontal(); + return new EntryData(path); + } + + public static implicit operator EntryData(Object obj) + { + return new EntryData(obj); + } - EditorGUILayout.EndVertical(); + #endregion } + + [Serializable] + public class SaveData + { + #region Public Variables + + public bool AutoClose; + public bool ShowFullPath; + public bool ShowFullPathForFolders = true; + public bool VisualMode; + public List EntryData = new List(); + public PingTypes PingType; + + #endregion + + #region Constructor + + public SaveData( + List entryData , PingTypes pingType , bool visualMode , bool autoClose , bool showFullPath , + bool showFullPathForFolders) + { + EntryData = entryData; + PingType = pingType; + VisualMode = visualMode; + AutoClose = autoClose; + ShowFullPath = showFullPath; + ShowFullPathForFolders = showFullPathForFolders; + } + + public SaveData() { } + + #endregion + + #region Public Methods + + public void Save() + { + IOHelper.ClearData(SETTINGS_FILENAME); + IOHelper.WriteToDisk(SETTINGS_FILENAME , this); + } + + #endregion + } + + #endregion } } - public enum MainHeaders { - Scenes, - Prefabs, + Scenes , + Prefabs , Scripts } + public enum ButtonTypes { - Standard, - Big, - SmallLongHeight, + Standard , + Big , + SmallLongHeight , SmallNormalHeight } + public enum PingTypes { - Ping, - Selection, - Both + Ping , + Selection , + Both , OpenAndSelect } \ No newline at end of file