This commit is contained in:
2025-05-16 23:31:59 +08:00
parent 9e4fef3f1e
commit d891e3f0ee
1198 changed files with 274242 additions and 1558 deletions

View File

@@ -0,0 +1,824 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace RapidIcon_1_7_2
{
//---ObjectPathPair Definition---//
public struct ObjectPathPair
{
public ObjectPathPair(UnityEngine.Object obj, string pth)
{
UnityEngine_object = obj;
path = pth;
}
public UnityEngine.Object UnityEngine_object;
public string path;
};
[Serializable]
public class AssetGrid
{
//---PUBLIC---//
//Icons
public Dictionary<UnityEngine.Object, IconSet> objectIconSets;
public Dictionary<string, IconSet> sortedIconSetsByPath;
public List<IconSet> visibleIconSets;
public List<IconSet> selectedIconSets;
//Textures
public Texture2D[] assetSelectionTextures;
//Other
public string rapidIconRootFolder;
public bool assetGridFocused;
public int previewSize;
//---INTERNAL---//
//GUI
Vector2 scrollPosition;
GUIStyle gridStyle, gridLabelStyle;
//Selection
int lastSelectedIconIndex;
int selectionMinIndex;
int selectionMaxIndex;
string lastSelectedIndividualFolder;
List<ObjectPathPair> objectsLoadedFromSelectedFolders;
//RapidIcon Window Elements
RapidIconWindow window;
AssetList assetList;
//Filter
int filterIdx;
string[] filters = new string[] { "t:model t:prefab", "t:prefab", "t:model" };
string[] filterNames = new string[] { "Prefabs & Models", "Prefabs Only", "Models Only" };
//Other
Rect rect;
bool iconsRefreshed;
public AssetGrid(AssetList assets)
{
//---Initialise AssetGrid---//
//Asset List
assetList = assets;
//Selection
objectsLoadedFromSelectedFolders = new List<ObjectPathPair>();
lastSelectedIconIndex = -1;
selectionMinIndex = int.MaxValue;
selectionMaxIndex = -1;
//Icons
objectIconSets = new Dictionary<UnityEngine.Object, IconSet>();
sortedIconSetsByPath = new Dictionary<string, IconSet>();
selectedIconSets = new List<IconSet>();
//Styles
previewSize = 128;
gridStyle = new GUIStyle();
gridStyle.fixedHeight = previewSize;
gridStyle.fixedWidth = previewSize;
gridStyle.margin.bottom = 16 + (int)EditorGUIUtility.singleLineHeight + 2;
gridStyle.margin.left = 16;
gridStyle.alignment = TextAnchor.MiddleCenter;
gridLabelStyle = new GUIStyle(gridStyle);
gridLabelStyle.margin.bottom = 16 + previewSize + 2;
gridLabelStyle.fixedHeight = EditorGUIUtility.singleLineHeight;
gridLabelStyle.alignment = TextAnchor.MiddleCenter;
if (EditorGUIUtility.isProSkin)
gridLabelStyle.normal.textColor = new Color32(192, 192, 192, 255);
else
gridLabelStyle.normal.textColor = Color.black;
//Filter
filterIdx = 0;
//Textures
assetSelectionTextures = new Texture2D[5];
string[] split = AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("RapidIconWindow")[0]).Split('/');
rapidIconRootFolder = "";
for (int i = 0; i < split.Length - 4; i++)
rapidIconRootFolder += split[i] + "/";
assetSelectionTextures[0] = (Texture2D)AssetDatabase.LoadMainAssetAtPath(rapidIconRootFolder + "Editor/UI/deselectedAsset.png");
assetSelectionTextures[1] = (Texture2D)AssetDatabase.LoadMainAssetAtPath(rapidIconRootFolder + "Editor/UI/selectedAssetActiveDark.png");
assetSelectionTextures[2] = (Texture2D)AssetDatabase.LoadMainAssetAtPath(rapidIconRootFolder + "Editor/UI/selectedAssetInactiveDark.png");
assetSelectionTextures[3] = (Texture2D)AssetDatabase.LoadMainAssetAtPath(rapidIconRootFolder + "Editor/UI/selectedAssetActiveLight.png");
assetSelectionTextures[4] = (Texture2D)AssetDatabase.LoadMainAssetAtPath(rapidIconRootFolder + "Editor/UI/selectedAssetInactiveLight.png");
assetSelectionTextures[0].hideFlags = HideFlags.DontSave;
assetSelectionTextures[1].hideFlags = HideFlags.DontSave;
assetSelectionTextures[2].hideFlags = HideFlags.DontSave;
assetList.lastNumberOfSelected = -1;
//Other
iconsRefreshed = true;
}
public void Draw(float width, RapidIconWindow w)
{
//---Check variables are set---//
CheckAndSetWindow(w);
//---Refresh icons after startup---//
if (!iconsRefreshed && EditorApplication.timeSinceStartup > 15)
{
RefreshAllIcons();
iconsRefreshed = true;
}
GUILayout.BeginVertical(GUILayout.Width(width));
GUILayout.Space(4);
//---Filter---//
GUILayout.BeginHorizontal();
GUILayout.Space(8);
if (GUILayout.Button("Refresh"))
ReloadObjects();
if (GUILayout.Button("Filter: " + filterNames[filterIdx]))
{
filterIdx++;
if (filterIdx == 3)
filterIdx = 0;
ReloadObjects();
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
//---Scroll view----//
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false, GUIStyle.none, GUI.skin.verticalScrollbar);
//---Draw icons---//
DrawIcons(width);
//---End GUI elements---//
GUILayout.EndScrollView();
GUILayout.EndVertical();
//---Get last rect and check focus---//
if (Event.current.type == EventType.Repaint)
rect = new Rect(GUILayoutUtility.GetLastRect());
CheckFocus(rect);
}
public void SaveData()
{
//---Save selected assets---//
string selectedAssetsString = "";
foreach (KeyValuePair<UnityEngine.Object, IconSet> iconSet in objectIconSets)
{
selectedAssetsString += "|-A-|" + iconSet.Value.assetPath + "|-S-|" + iconSet.Value.selected;
}
EditorPrefs.SetString(PlayerSettings.productName + "RapidIconSelectedAssets", selectedAssetsString);
//---Save other variables---//
EditorPrefs.SetFloat(PlayerSettings.productName + "RapidIconAssetGridScroll", scrollPosition.y);
EditorPrefs.SetBool(PlayerSettings.productName + "RapidIconIconsRefreshed", iconsRefreshed);
EditorPrefs.SetInt(PlayerSettings.productName + "RapidIconFilterIdx", filterIdx);
}
public void LoadData()
{
//---Close RapidIcon window if left open when Unity starts---//
if (!SessionState.GetBool("rapidicon_loaded", false))
{
SessionState.SetBool("rapidicon_forceclose", true);
SessionState.SetBool("rapidicon_loaded", true);
return;
}
//---Load objects in selected folders---//
objectsLoadedFromSelectedFolders = LoadObjectsInSelectedFolders();
CreateIconSets();
//---Load selected assets---//
string selectedAssetsString = EditorPrefs.GetString(PlayerSettings.productName + "RapidIconSelectedAssets");
string[] splitAssets = selectedAssetsString.Split(new string[] { "|-A-|" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in splitAssets)
{
string[] splitS = s.Split(new string[] { "|-S-|" }, StringSplitOptions.RemoveEmptyEntries);
string assetPath = splitS[0];
if (splitS[1] == "True")
{
IconSet iconSet = GetIconSetFromPath(assetPath);
if (iconSet != null)
{
iconSet.selected = true;
selectedIconSets.Add(GetIconSetFromPath(assetPath));
}
}
}
//---Load other variables---//
iconsRefreshed = EditorPrefs.GetBool(PlayerSettings.productName + "RapidIconIconsRefreshed");
scrollPosition = new Vector2(0, EditorPrefs.GetFloat(PlayerSettings.productName + "RapidIconAssetGridScroll"));
filterIdx = EditorPrefs.GetInt(PlayerSettings.productName + "RapidIconFilterIdx", 0);
}
void ReloadObjects()
{
//---Unload objects
EditorUtility.UnloadUnusedAssetsImmediate();
//---Reload the objects from selected folders---//
objectsLoadedFromSelectedFolders = LoadObjectsInSelectedFolders();
CreateIconSets();
//---Add loaded icons to list---///
sortedIconSetsByPath.Clear();
foreach (ObjectPathPair loadedObject in objectsLoadedFromSelectedFolders)
{
IconSet iconSet = objectIconSets[loadedObject.UnityEngine_object];
sortedIconSetsByPath.Add(iconSet.assetPath, iconSet);
}
//---Sort the list by path---//
sortedIconSetsByPath = SortIconSetsByFolder(sortedIconSetsByPath);
//---Update variables---//
assetList.lastNumberOfSelected = assetList.selectedFolders.Count;
lastSelectedIndividualFolder = assetList.selectedFolders[0];
}
public void RefreshAllIcons()
{
//---Loop through all icons---//
int index = 1;
foreach (IconSet iconSet in objectIconSets.Values)
{
//---Show a progress bar---//
EditorUtility.DisplayProgressBar("Updating Icons (" + index++ + "/" + objectIconSets.Count + ")", iconSet.assetPath, (float)(index) / (float)(objectIconSets.Count));
//---Update the icon renders---//
Vector2Int renderResolution = Utils.MutiplyVector2IntByFloat(iconSet.GetCurrentIcon().iconSettings.exportResolution, window.iconEditor.resMultiplyers[window.iconEditor.resMultiplyerIndex]);
iconSet.GetCurrentIcon().UpdateIcon(renderResolution, new Vector2Int(128, (int)(((float)renderResolution.y / (float)renderResolution.x) * 128)));
}
//---Clear the progress bar when done---//
EditorUtility.ClearProgressBar();
}
void CheckAndSetWindow(RapidIconWindow w)
{
if (!window)
window = w;
}
List<ObjectPathPair> LoadObjectsInSelectedFolders()
{
//---Get asset paths of all assets in selected folders---//
string[] assetGUIDs = AssetDatabase.FindAssets(filters[filterIdx], assetList.selectedFolders.ToArray());
string[] assetPaths = new string[assetGUIDs.Length];
for (int i = 0; i < assetGUIDs.Length; i++)
assetPaths[i] = AssetDatabase.GUIDToAssetPath(assetGUIDs[i]);
List<ObjectPathPair> loadedObjectPathPairs = new List<ObjectPathPair>();
foreach (string assetPath in assetPaths)
{
//---Get folder path from each of the asset paths---//
string[] split = assetPath.Split('/');
string folderPath = "";
for (int i = 0; i < split.Length - 1; i++)
folderPath += split[i] + (i < split.Length - 2 ? "/" : "");
//---Load the asset if the path is in the selected folders list---//
if (assetList.selectedFolders.Contains(folderPath))
{
ObjectPathPair objectPathPair = new ObjectPathPair();
UnityEngine.Object o = AssetDatabase.LoadMainAssetAtPath(assetPath);
objectPathPair.UnityEngine_object = o;
objectPathPair.path = assetPath;
loadedObjectPathPairs.Add(objectPathPair);
}
}
return loadedObjectPathPairs;
}
void CreateIconSets()
{
int index = 1;
foreach (ObjectPathPair loadedObject in objectsLoadedFromSelectedFolders)
{
if (!objectIconSets.ContainsKey(loadedObject.UnityEngine_object))
{
//---Create icon if doesn't already exist---//
EditorUtility.DisplayProgressBar("Generating Icon Previews (" + index + " / " + (objectsLoadedFromSelectedFolders.Count) + ")", loadedObject.path, (float)(index++) / (float)objectsLoadedFromSelectedFolders.Count);
objectIconSets.Add(loadedObject.UnityEngine_object, CreateIconSet(loadedObject));
}
else if (objectIconSets[loadedObject.UnityEngine_object].deleted)
{
objectIconSets[loadedObject.UnityEngine_object].deleted = false;
}
else
{
//---Update asset path if changed---//
IconSet iconSet = objectIconSets[loadedObject.UnityEngine_object];
string currentPath = AssetDatabase.GetAssetPath(loadedObject.UnityEngine_object);
string savedPath = iconSet.assetPath;
if (savedPath != currentPath)
{
Debug.LogWarning("Path updated for " + iconSet.assetName + " from " + savedPath + " to " + currentPath);
iconSet.assetPath = currentPath;
string[] split;
split = iconSet.assetPath.Split('/');
iconSet.assetName = split[split.Length - 1];
if (iconSet.assetName.Length > 19)
iconSet.assetShortenedName = iconSet.assetName.Substring(0, 16) + "...";
else
iconSet.assetShortenedName = iconSet.assetName;
split = iconSet.assetPath.Split('/');
iconSet.folderPath = "";
for (int i = 0; i < split.Length - 1; i++)
iconSet.folderPath += split[i] + (i < split.Length - 2 ? "/" : "");
}
}
}
EditorUtility.ClearProgressBar();
}
public IconSet CreateIconSet(ObjectPathPair objectPathPair)
{
//---Create a new icon set and icon objects---//
IconSet iconSet = new IconSet(this, objectPathPair);
return iconSet;
}
void DrawIcons(float gridWidth)
{
//---Draw margin---//
GUILayout.Space(14);
GUILayout.BeginHorizontal();
GUILayout.Space(16);
//---Create lists---//
List<Texture2D> visibleIconRenders = new List<Texture2D>();
List<Texture2D> visibleIconSelectionTextures = new List<Texture2D>();
List<string> visibleIconLabels = new List<string>();
visibleIconSets = new List<IconSet>();
//---Reload objects if needed---//
if (sortedIconSetsByPath.Count != objectsLoadedFromSelectedFolders.Count || assetList.selectedFolders.Count != assetList.lastNumberOfSelected || assetList.selectedFolders[0] != lastSelectedIndividualFolder)
{
ReloadObjects();
}
//---Deselect icons if no longer in selected folders / search (i.e. if not visible in the grid)---//
foreach (IconSet iconSet in objectIconSets.Values)
{
if (!assetList.selectedFolders.Contains(iconSet.folderPath) || (assetList.doSearch && !assetList.searchFolders.Contains(iconSet.folderPath + "/" + iconSet.assetName)))
{
iconSet.selected = false;
if (selectedIconSets.Contains(iconSet))
selectedIconSets.Remove(iconSet);
}
}
int index = 0;
foreach (KeyValuePair<string, IconSet> iconSet in sortedIconSetsByPath)
{
//---Skip this icon if it's flagged as deleted---//
if (iconSet.Value.deleted)
continue;
//---Flag the icon as deleted if asset object is null---//
else if (iconSet.Value.assetObject == null)
{
iconSet.Value.deleted = true;
iconSet.Value.assetObject = null;
selectedIconSets.Remove(iconSet.Value);
continue;
}
//---Render the icon preview if it is missing---//
if (iconSet.Value.GetCurrentIcon().previewRender == null)
{
EditorUtility.DisplayProgressBar("Generating Icon Previews (" + index + "/" + (sortedIconSetsByPath.Count) + ")", iconSet.Value.assetPath, ((float)index++ / sortedIconSetsByPath.Count));
iconSet.Value.GetCurrentIcon().previewRender = Utils.RenderIcon(iconSet.Value.GetCurrentIcon(), previewSize, (int)(((float)iconSet.Value.GetCurrentIcon().iconSettings.exportResolution.y / (float)iconSet.Value.GetCurrentIcon().iconSettings.exportResolution.x) * previewSize));
}
//---Set the selection texture---//
if (EditorGUIUtility.isProSkin)
iconSet.Value.selectionTexture = iconSet.Value.selected ? (assetGridFocused ? assetSelectionTextures[1] : assetSelectionTextures[2]) : assetSelectionTextures[0];
else
iconSet.Value.selectionTexture = iconSet.Value.selected ? (assetGridFocused ? assetSelectionTextures[3] : assetSelectionTextures[4]) : assetSelectionTextures[0];
//---Add the icon to visibleIcons if it's within the selected folders, or the search---//
if (assetList.selectedFolders.Contains(iconSet.Value.folderPath) && (!assetList.doSearch || assetList.searchFolders.Contains(iconSet.Value.folderPath + "/" + iconSet.Value.assetName)))
{
visibleIconSets.Add(iconSet.Value);
//Use warning image if animations enabled
visibleIconRenders.Add(iconSet.Value.GetCurrentIcon().previewRender);
visibleIconSelectionTextures.Add(iconSet.Value.selectionTexture);
visibleIconLabels.Add(iconSet.Value.assetShortenedName);
}
}
EditorUtility.ClearProgressBar();
//---Draw the grid of icons---///
int count = Mathf.FloorToInt((gridWidth - 16) / (previewSize + 16));
count = Mathf.Min(count, visibleIconSets.Count);
int clicked = GUILayout.SelectionGrid(-1, visibleIconRenders.ToArray(), count, gridStyle, GUILayout.Width(32 + count * (previewSize + 16)));
Rect r = GUILayoutUtility.GetLastRect();
r.y += previewSize + 2;
//---Draw the label background textures on the grid---//
int labelClicked = GUI.SelectionGrid(r, -1, visibleIconSelectionTextures.ToArray(), count, gridLabelStyle);
//---Draw the label texts on the grid---//
clicked = GUI.SelectionGrid(r, clicked, visibleIconLabels.ToArray(), count, gridLabelStyle);
if (clicked == -1 && labelClicked != -1)
clicked = labelClicked;
//---Draw margin and end GUI elements---//
GUILayout.Space(16);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
//---Check mouse clicks and arrow key presses for grid selection---//
CheckMouseClicks(clicked, visibleIconSets);
CheckArrowKeys(visibleIconSets, count);
}
void CheckMouseClicks(int clicked, List<IconSet> visibleIconSets)
{
if (clicked >= 0)
{
if (!Event.current.control && !Event.current.shift)
{
//---Regular click, no ctrl/shift - select the icon---//
foreach (KeyValuePair<UnityEngine.Object, IconSet> iconSet in objectIconSets)
iconSet.Value.selected = false;
visibleIconSets[clicked].selected = true;
visibleIconSets[clicked].assetGridIconIndex = clicked;
selectedIconSets.Clear();
selectionMinIndex = clicked;
selectionMaxIndex = clicked;
}
else if (Event.current.control)
{
//---Ctrl click - add icon to existing selection---//
visibleIconSets[clicked].selected = !visibleIconSets[clicked].selected;
visibleIconSets[clicked].assetGridIconIndex = clicked;
}
else if (Event.current.shift)
{
//---Shift click - add all icons between clicks---//
if (selectionMinIndex != -1 && selectionMaxIndex != -1 && clicked >= selectionMinIndex && clicked <= selectionMaxIndex)
{
for (int i = selectionMinIndex; i <= selectionMaxIndex; i++)
{
visibleIconSets[i].selected = false;
if (selectedIconSets.Contains(visibleIconSets[i]))
selectedIconSets.Remove(visibleIconSets[i]);
}
selectionMinIndex = Mathf.Min(lastSelectedIconIndex, clicked);
selectionMaxIndex = Math.Max(lastSelectedIconIndex, clicked);
}
int minI = Mathf.Min(lastSelectedIconIndex, clicked);
int maxI = Math.Max(lastSelectedIconIndex, clicked);
if (minI < 0) minI = 0;
if (maxI < 0) maxI = 0;
for (int i = minI; i <= maxI; i++)
{
visibleIconSets[i].selected = true;
visibleIconSets[i].assetGridIconIndex = i;
if (!selectedIconSets.Contains(visibleIconSets[i]))
selectedIconSets.Add(visibleIconSets[i]);
}
}
//---If not shift click then toggle the icon from the selection---//
if (!Event.current.shift)
{
if (visibleIconSets[clicked].selected && !selectedIconSets.Contains(visibleIconSets[clicked]))
selectedIconSets.Add(visibleIconSets[clicked]);
else if (selectedIconSets.Contains(visibleIconSets[clicked]))
selectedIconSets.Remove(visibleIconSets[clicked]);
}
//---Sort the selected icons by grid index---//
if (selectedIconSets.Count > 1)
selectedIconSets = selectedIconSets.OrderBy(a => a.assetGridIconIndex).ToList();
//---Update variables---//
selectionMinIndex = Mathf.Min(selectionMinIndex, clicked);
selectionMaxIndex = Mathf.Max(selectionMaxIndex, clicked);
lastSelectedIconIndex = clicked;
assetGridFocused = true;
window.Repaint();
}
else if (Event.current.rawType == EventType.MouseDown && !window.leftSeparator.mouseOver && !window.rightSeparator.mouseOver)
{
//---Clear selection if mouse clicked in empty space in asset grid region---//
Vector2 correctMousePos = Event.current.mousePosition + rect.position;
if (rect.Contains(correctMousePos))
{
selectedIconSets.Clear();
foreach (IconSet iconSet in visibleIconSets)
iconSet.selected = false;
}
}
}
void CheckArrowKeys(List<IconSet> iconSets, int gridXIcons)
{
//---Check if a key is pressed---//
if (assetGridFocused && Event.current.isKey && Event.current.type != EventType.KeyUp)
{
//---Right arrow key pressed---//
if (Event.current.keyCode == KeyCode.RightArrow && lastSelectedIconIndex < iconSets.Count - 1)
{
if (!Event.current.shift && !Event.current.control)
{
//---Select only this icon if no shift/ctrl pressed---//
foreach (IconSet iconSet in iconSets)
iconSet.selected = false;
selectedIconSets.Clear();
iconSets[lastSelectedIconIndex + 1].selected = true;
selectedIconSets.Add(iconSets[lastSelectedIconIndex + 1]);
}
else
{
//---Add to current selection if shift/ctrl pressed---///
if (!iconSets[lastSelectedIconIndex + 1].selected)
{
iconSets[lastSelectedIconIndex + 1].selected = true;
selectedIconSets.Add(iconSets[lastSelectedIconIndex + 1]);
}
else
{
iconSets[lastSelectedIconIndex].selected = false;
selectedIconSets.Remove(iconSets[lastSelectedIconIndex]);
}
}
lastSelectedIconIndex++;
}
//---Left arrow key pressed---//
else if (Event.current.keyCode == KeyCode.LeftArrow && lastSelectedIconIndex > 0)
{
if (!Event.current.shift && !Event.current.control)
{
//---Select only this icon if no shift/ctrl pressed---//
foreach (IconSet iconSet in iconSets)
iconSet.selected = false;
selectedIconSets.Clear();
iconSets[lastSelectedIconIndex - 1].selected = true;
selectedIconSets.Add(iconSets[lastSelectedIconIndex - 1]);
}
else
{
//---Add to current selection if shift/ctrl pressed---///
if (!iconSets[lastSelectedIconIndex - 1].selected)
{
iconSets[lastSelectedIconIndex - 1].selected = true;
selectedIconSets.Add(iconSets[lastSelectedIconIndex - 1]);
}
else
{
iconSets[lastSelectedIconIndex].selected = false;
selectedIconSets.Remove(iconSets[lastSelectedIconIndex]);
}
}
lastSelectedIconIndex--;
}
//---Down arrow key pressed---//
else if (Event.current.keyCode == KeyCode.DownArrow)
{
if (lastSelectedIconIndex < iconSets.Count - gridXIcons)
{
if (!Event.current.shift && !Event.current.control)
{
//---Select only this icon if no shift/ctrl pressed---//
foreach (IconSet iconSet in iconSets)
iconSet.selected = false;
selectedIconSets.Clear();
iconSets[lastSelectedIconIndex + gridXIcons].selected = true;
selectedIconSets.Add(iconSets[lastSelectedIconIndex + gridXIcons]);
}
else
{
//---Add to current selection if shift/ctrl pressed---///
if (!iconSets[lastSelectedIconIndex + gridXIcons].selected)
{
iconSets[lastSelectedIconIndex + gridXIcons].selected = true;
selectedIconSets.Add(iconSets[lastSelectedIconIndex + gridXIcons]);
for (int i = lastSelectedIconIndex; i < lastSelectedIconIndex + gridXIcons; i++)
{
iconSets[i].selected = true;
selectedIconSets.Add(iconSets[i]);
}
}
else
{
iconSets[lastSelectedIconIndex].selected = false;
selectedIconSets.Remove(iconSets[lastSelectedIconIndex]);
for (int i = lastSelectedIconIndex; i < lastSelectedIconIndex + gridXIcons; i++)
{
iconSets[i].selected = false;
selectedIconSets.Remove(iconSets[i]);
}
}
}
lastSelectedIconIndex += gridXIcons;
}
else if (lastSelectedIconIndex < Mathf.Floor((float)iconSets.Count / gridXIcons) * gridXIcons)
{
if (!Event.current.shift && !Event.current.control)
{
//---Select only this icon if no shift/ctrl pressed---//
foreach (IconSet iconSet in iconSets)
iconSet.selected = false;
selectedIconSets.Clear();
iconSets[iconSets.Count - 1].selected = true;
selectedIconSets.Add(iconSets[iconSets.Count - 1]);
}
else
{
//---Add to current selection if shift/ctrl pressed---///
if (!iconSets[iconSets.Count - 1].selected)
{
iconSets[iconSets.Count - 1].selected = true;
selectedIconSets.Add(iconSets[iconSets.Count - 1]);
for (int i = lastSelectedIconIndex; i < iconSets.Count; i++)
{
iconSets[i].selected = true;
selectedIconSets.Add(iconSets[i]);
}
}
else
{
iconSets[lastSelectedIconIndex].selected = false;
selectedIconSets.Remove(iconSets[lastSelectedIconIndex]);
for (int i = lastSelectedIconIndex; i < iconSets.Count - 1; i++)
{
iconSets[i].selected = false;
selectedIconSets.Remove(iconSets[i]);
}
}
}
lastSelectedIconIndex = iconSets.Count - 1;
}
}
//---Up arrow key pressed---//
else if (Event.current.keyCode == KeyCode.UpArrow && lastSelectedIconIndex >= gridXIcons)
{
if (!Event.current.shift && !Event.current.control)
{
//---Select only this icon if no shift/ctrl pressed---//
foreach (IconSet iconSet in iconSets)
iconSet.selected = false;
selectedIconSets.Clear();
iconSets[lastSelectedIconIndex - gridXIcons].selected = true;
selectedIconSets.Add(iconSets[lastSelectedIconIndex - gridXIcons]);
}
else
{
//---Add to current selection if shift/ctrl pressed---///
if (!iconSets[lastSelectedIconIndex - gridXIcons].selected)
{
iconSets[lastSelectedIconIndex - gridXIcons].selected = true;
selectedIconSets.Add(iconSets[lastSelectedIconIndex - gridXIcons]);
for (int i = lastSelectedIconIndex; i > lastSelectedIconIndex - gridXIcons; i--)
{
iconSets[i].selected = true;
selectedIconSets.Add(iconSets[i]);
}
}
else
{
iconSets[lastSelectedIconIndex].selected = false;
selectedIconSets.Remove(iconSets[lastSelectedIconIndex]);
for (int i = lastSelectedIconIndex; i > lastSelectedIconIndex - gridXIcons; i--)
{
iconSets[i].selected = false;
selectedIconSets.Remove(iconSets[i]);
}
}
}
lastSelectedIconIndex -= gridXIcons;
}
else if (Event.current.keyCode == KeyCode.A && Event.current.modifiers == EventModifiers.Control)
{
//---Select all if ctrl-A pressed---//
selectedIconSets.Clear();
foreach (KeyValuePair<string, IconSet> iconSet in sortedIconSetsByPath)
{
if (assetList.selectedFolders.Contains(iconSet.Value.folderPath))
{
iconSet.Value.selected = true;
selectedIconSets.Add(iconSet.Value);
}
}
}
}
}
Dictionary<string, IconSet> SortIconSetsByFolder(Dictionary<string, IconSet> data)
{
//---Get a string array of asset paths---//
string[] assetPaths = new string[data.Keys.Count];
data.Keys.CopyTo(assetPaths, 0);
//---Create a dictionary that will hold folder paths as keys, and a list of asset paths in the values (assets within the folder)---//
Dictionary<string, List<string>> folders = new Dictionary<string, List<string>>();
//---Create a list for just the folder names---//
List<string> folderNames = new List<string>();
foreach (string assetPath in assetPaths)
{
//---Get folder path from asset path---//
string[] split = assetPath.Split('/');
string folderPath = "";
for (int i = 0; i < split.Length - 1; i++)
folderPath += split[i] + (i < split.Length - 2 ? "/" : "");
//---Add folder to folders dictionary if not already in there---//
if (!folders.ContainsKey(folderPath))
{
folders.Add(folderPath, new List<string>());
folderNames.Add(folderPath);
}
//---Add asset path in the list at the [folderPath] index of the folders dictionary---//
folders[folderPath].Add(assetPath);
}
//---Sort the folder names---//
folderNames.Sort();
//---For each of the sorted folders, sort the assets within that folder---//
string[] sortedAssetPaths = new string[assetPaths.Length];
int index = 0;
foreach (string folder in folderNames)
{
folders[folder].Sort();
foreach (string assetPath in folders[folder])
{
//---Add the asset paths to the new list in sorted order---//
sortedAssetPaths[index++] = assetPath;
}
}
//---Use the sorted list of asset paths to create a dictionary of sorted icons---//
Dictionary<string, IconSet> sortedData = new Dictionary<string, IconSet>();
foreach (string assetPath in sortedAssetPaths)
{
sortedData.Add(assetPath, data[assetPath]);
}
return sortedData;
}
void CheckFocus(Rect checkRect)
{
//---Check if last mouse click was in the asset grid rect---//
if (Event.current.rawType == EventType.MouseDown)
{
assetGridFocused = checkRect.Contains(Event.current.mousePosition);
}
//---Check the RapidIcon window is in focus---//
if (EditorWindow.focusedWindow != null && EditorWindow.focusedWindow.GetType() != typeof(RapidIconWindow))
assetGridFocused = false;
}
IconSet GetIconSetFromPath(string path)
{
//---Loop through icons and check if the path matches---//
foreach (IconSet iconSet in objectIconSets.Values)
{
if (iconSet.assetPath == path)
return iconSet;
}
return null;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c67b68295a3db64db12b09928f40b1f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,582 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace RapidIcon_1_7_2
{
[Serializable]
public class AssetList
{
//---PUBLIC---///
//Selected folders
public List<string> selectedFolders;
public int lastNumberOfSelected;
//Search
public bool doSearch;
public List<string> searchFolders;
//---INTERNAL---//
//Foldouts
bool foldoutColoursSet;
GUIStyle foldoutStyle, foldoutStyleSelected;
Dictionary<string, bool> foldoutStates;
bool foldoutsUpdated;
List<string> visibleFolders;
//Selection
string selectionMinFolder, selectionMaxFolder, firstSelectedFolder, lastSelectedFolder, selectFolder;
int arrowSelectedFolder;
//Textures
Texture2D[] selectionTextures;
Texture2D[] folderIcons;
//Search
string searchString;
//Other
RapidIconWindow window;
bool assetListFocused, initialised;
string rootFolder;
Vector2 scrollPosition;
public AssetList(string appDataPath)
{
//---Initialise AssetList---//
//Foldouts
foldoutColoursSet = false;
foldoutStyle = foldoutStyleSelected = new GUIStyle();
foldoutStates = new Dictionary<string, bool>();
visibleFolders = new List<string>();
foldoutsUpdated = false;
//Search
searchFolders = new List<string>();
searchString = "";
doSearch = false;
//Selection
selectionTextures = new Texture2D[2];
if (EditorGUIUtility.isProSkin)
{
selectionTextures[0] = Utils.CreateColourTexture(2, 2, new Color32(44, 93, 135, 255));
selectionTextures[1] = Utils.CreateColourTexture(2, 2, new Color32(77, 77, 77, 255));
}
else
{
selectionTextures[0] = Utils.CreateColourTexture(2, 2, new Color32(58, 114, 176, 255));
selectionTextures[1] = Utils.CreateColourTexture(2, 2, new Color32(174, 174, 174, 255));
}
selectionTextures[0].hideFlags = HideFlags.DontSave;
selectionTextures[1].hideFlags = HideFlags.DontSave;
arrowSelectedFolder = 0;
selectedFolders = new List<string>();
firstSelectedFolder = "";
lastSelectedFolder = "";
selectionMinFolder = "";
selectionMaxFolder = "";
selectFolder = "";
//Root Paths
string[] rootFolderSplit = appDataPath.Split('/');
rootFolder = rootFolderSplit[rootFolderSplit.Length - 1];
string[] split = AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("RapidIcon")[0]).Split('/');
string rapidIconRootFolder = "";
for (int i = 0; i < split.Length; i++)
rapidIconRootFolder += split[i] + "/";
//Folder Icons
folderIcons = new Texture2D[4];
folderIcons[0] = (Texture2D)AssetDatabase.LoadMainAssetAtPath(rapidIconRootFolder + "Editor/UI/folderIconClosedDark.png");
folderIcons[1] = (Texture2D)AssetDatabase.LoadMainAssetAtPath(rapidIconRootFolder + "Editor/UI/folderIconOpenDark.png");
folderIcons[2] = (Texture2D)AssetDatabase.LoadMainAssetAtPath(rapidIconRootFolder + "Editor/UI/folderIconClosedLight.png");
folderIcons[3] = (Texture2D)AssetDatabase.LoadMainAssetAtPath(rapidIconRootFolder + "Editor/UI/folderIconOpenLight.png");
//Other
assetListFocused = true;
}
public void Draw(float width, RapidIconWindow w)
{
//---Check variables are set---//
CheckAndSetWindow(w);
CheckAndSetFoldoutColours();
CheckArrowKeys();
//---Search Bar---//
GUILayout.BeginVertical(GUILayout.Width(width));
EditorGUI.BeginChangeCheck();
searchString = GUILayout.TextField(searchString);
if (searchString == "")
{
Rect r = GUILayoutUtility.GetLastRect();
GUI.Label(r, "Search Models and Prefabs");
searchFolders.Clear();
doSearch = false;
}
else if (EditorGUI.EndChangeCheck())
{
doSearch = true;
searchFolders.Clear();
string[] results = AssetDatabase.FindAssets(searchString);
if (results.Length > 0)
{
foreach (string guid in results)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
if (AssetDatabase.GetMainAssetTypeAtPath(path) == typeof(GameObject))
{
searchFolders.Add(path);
}
}
}
}
//---Draw asset list folders---//
visibleFolders.Clear();
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false, GUIStyle.none, GUI.skin.verticalScrollbar, GUILayout.Width(width));
if (!foldoutsUpdated)
{
UpdateFoldoutStates(rootFolder, true);
foldoutsUpdated = true;
}
DrawAllSubFolders(rootFolder, 0, width);
if (selectFolder != "")
{
SelectFolder(selectFolder, 0);
selectFolder = "";
}
GUILayout.EndScrollView();
GUILayout.EndVertical();
//---Check if asset list is focused---//
CheckFocus(GUILayoutUtility.GetLastRect());
}
public void SaveData()
{
//---Save all opened folders---//
string openedFoldersString = "";
foreach (KeyValuePair<string, bool> foldoutState in foldoutStates)
{
if (foldoutState.Value)
openedFoldersString += "|-F-|" + foldoutState.Key;
}
EditorPrefs.SetString(PlayerSettings.productName + "RapidIconOpenedFolders", openedFoldersString);
//---Save all selected folders---//
string selectedFoldersString = "";
foreach (string folder in selectedFolders)
{
selectedFoldersString += "|-F-|" + folder;
}
EditorPrefs.SetString(PlayerSettings.productName + "RapidIconSelectedFolders", selectedFoldersString);
}
public void LoadData()
{
//---Load all opened folders---//
string openedFoldersString = EditorPrefs.GetString(PlayerSettings.productName + "RapidIconOpenedFolders");
string[] openedFoldersSplit = openedFoldersString.Split(new string[] { "|-F-|" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string folder in openedFoldersSplit)
foldoutStates.Add(folder, true);
//---Load all selected folders---//
string selectedFoldersString = EditorPrefs.GetString(PlayerSettings.productName + "RapidIconSelectedFolders");
string[] selectedFoldersSplit = selectedFoldersString.Split(new string[] { "|-F-|" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string folder in selectedFoldersSplit)
selectedFolders.Add(folder);
if (selectedFolders.Count == 0)
selectedFolders.Add(rootFolder);
selectedFolders.Sort();
}
void CheckAndSetWindow(RapidIconWindow w)
{
if (!window)
window = w;
}
void CheckAndSetFoldoutColours()
{
if (!foldoutColoursSet)
{
foldoutStyle = new GUIStyle(EditorStyles.foldout);
foldoutStyleSelected = new GUIStyle(EditorStyles.foldout);
Color txtCol = new Color32(192, 192, 192, 255);
if (EditorGUIUtility.isProSkin)
{
//---Set unselected foldout style---//
foldoutStyle.normal.textColor = txtCol;
foldoutStyle.onNormal.textColor = txtCol;
foldoutStyle.hover.textColor = txtCol;
foldoutStyle.onHover.textColor = txtCol;
foldoutStyle.focused.textColor = txtCol;
foldoutStyle.onFocused.textColor = txtCol;
foldoutStyle.active.textColor = txtCol;
foldoutStyle.onActive.textColor = txtCol;
//---Set selected foldout style---//
foldoutStyleSelected.normal.textColor = txtCol;
foldoutStyleSelected.onNormal.textColor = txtCol;
foldoutStyleSelected.hover.textColor = txtCol;
foldoutStyleSelected.onHover.textColor = txtCol;
foldoutStyleSelected.focused.textColor = txtCol;
foldoutStyleSelected.onFocused.textColor = txtCol;
foldoutStyleSelected.active.textColor = txtCol;
foldoutStyleSelected.onActive.textColor = txtCol;
}
else
{
//---Set unselected foldout style---//
foldoutStyle.normal.textColor = Color.black;
foldoutStyle.onNormal.textColor = Color.black;
foldoutStyle.hover.textColor = Color.black;
foldoutStyle.onHover.textColor = Color.black;
foldoutStyle.focused.textColor = Color.black;
foldoutStyle.onFocused.textColor = Color.black;
foldoutStyle.active.textColor = Color.black;
foldoutStyle.onActive.textColor = Color.black;
//---Set selected foldout style---//
foldoutStyleSelected.normal.textColor = Color.white;
foldoutStyleSelected.onNormal.textColor = Color.white;
foldoutStyleSelected.hover.textColor = Color.white;
foldoutStyleSelected.onHover.textColor = Color.white;
foldoutStyleSelected.focused.textColor = Color.white;
foldoutStyleSelected.onFocused.textColor = Color.white;
foldoutStyleSelected.active.textColor = Color.white;
foldoutStyleSelected.onActive.textColor = Color.white;
}
foldoutColoursSet = true;
}
}
void CheckArrowKeys()
{
//---Check if a key is pressed---//
if (assetListFocused && Event.current.isKey && Event.current.type != EventType.KeyUp)
{
//---Fold out folders if right arrow key pressed---//
if (Event.current.keyCode == KeyCode.RightArrow)
{
foreach (string f in selectedFolders)
{
//Fold out subfolders as well if alt pressed
if (Event.current.alt)
SetAllFoldoutChildren(f, true);
else
foldoutStates[f] = true;
}
GUIUtility.ExitGUI();
}
//---Collapse folders if left arrow key pressed---//
else if (Event.current.keyCode == KeyCode.LeftArrow)
{
foreach (string f in selectedFolders)
{
//Fold in subfolders as well if alt pressed
if (Event.current.alt)
SetAllFoldoutChildren(f, false);
else
foldoutStates[f] = false;
}
GUIUtility.ExitGUI();
}
//---Select folder below if down arrow key pressed---//
else if (Event.current.keyCode == KeyCode.DownArrow && arrowSelectedFolder < visibleFolders.Count - 1)
{
SelectFolder(visibleFolders[++arrowSelectedFolder], -1);
GUIUtility.ExitGUI();
}
//---Select folder above if up arrow key pressed---//
else if (Event.current.keyCode == KeyCode.UpArrow && arrowSelectedFolder > 0)
{
SelectFolder(visibleFolders[--arrowSelectedFolder], 1);
GUIUtility.ExitGUI();
}
}
}
void CheckFocus(Rect rect)
{
//---Check if last mouse click was in the asset list rect---//
if (Event.current.rawType == EventType.MouseDown)
assetListFocused = rect.Contains(Event.current.mousePosition);
if (assetListFocused)
window.assetGrid.assetGridFocused = false;
//---Check the RapidIcon window is in focus---//
if (EditorWindow.focusedWindow != null && EditorWindow.focusedWindow.GetType() != typeof(RapidIconWindow))
assetListFocused = false;
}
void SetAllFoldoutChildren(string folder, bool foldout)
{
//---Set foldout state of folder---//
if (!foldoutStates.ContainsKey(folder))
foldoutStates.Add(folder, foldout);
else
foldoutStates[folder] = foldout;
//---Set foldout state of sub folders---//
string[] subfolders = AssetDatabase.GetSubFolders(folder);
foreach (string subfolder in subfolders)
SetAllFoldoutChildren(subfolder, foldout);
}
void SelectFolder(string folder, int keyAdjust)
{
assetListFocused = true;
arrowSelectedFolder = visibleFolders.IndexOf(folder);
//---Select this folder only---//
if (!Event.current.control && !Event.current.shift)
{
selectedFolders.Clear();
selectedFolders.Add(folder);
firstSelectedFolder = folder;
lastSelectedFolder = folder;
selectionMinFolder = folder;
selectionMaxFolder = folder;
}
//---Control select, add folder to selection---//
else if (!Event.current.shift)
{
if (!selectedFolders.Contains(folder))
{
if (selectionMinFolder == "")
selectionMinFolder = folder;
if (selectionMaxFolder == "")
selectionMaxFolder = folder;
selectedFolders.Add(folder);
lastSelectedFolder = folder;
int lastSelectedFolderIndex = visibleFolders.IndexOf(lastSelectedFolder);
int selectionMinIndex = visibleFolders.IndexOf(selectionMinFolder);
if (selectionMinIndex == -1)
selectionMinIndex = lastSelectedFolderIndex;
int selectionMaxIndex = visibleFolders.IndexOf(selectionMaxFolder);
if (selectionMaxIndex == -1)
selectionMinIndex = lastSelectedFolderIndex;
selectionMinFolder = visibleFolders[Mathf.Min(lastSelectedFolderIndex, selectionMinIndex)];
selectionMaxFolder = visibleFolders[Mathf.Max(lastSelectedFolderIndex, selectionMaxIndex)];
}
else if (selectedFolders.Count > 1)
selectedFolders.Remove(visibleFolders[visibleFolders.IndexOf(folder) + keyAdjust]);
}
//---Shift select, select folder and folders inbetween---//
else
{
if (selectionMinFolder == "")
selectionMinFolder = folder;
if (selectionMaxFolder == "")
selectionMaxFolder = folder;
if (lastSelectedFolder == "")
lastSelectedFolder = folder;
if (firstSelectedFolder == "")
firstSelectedFolder = folder;
int thisFolderIndex = visibleFolders.IndexOf(folder);
int lastSelectedFolderIndex = visibleFolders.IndexOf(lastSelectedFolder);
int firstSelectedFolderIndex = visibleFolders.IndexOf(firstSelectedFolder);
int selectionMinIndex = visibleFolders.IndexOf(selectionMinFolder);
int selectionMaxIndex = visibleFolders.IndexOf(selectionMaxFolder);
if (selectionMinIndex == -1)
selectionMinIndex = int.MaxValue;
int minI = 0, maxI = -1;
if (thisFolderIndex >= selectionMinIndex && thisFolderIndex <= selectionMaxIndex)
{
selectedFolders.Clear();
minI = Mathf.Min(firstSelectedFolderIndex, thisFolderIndex);
maxI = Math.Max(firstSelectedFolderIndex, thisFolderIndex);
selectionMinFolder = visibleFolders[minI];
selectionMaxFolder = visibleFolders[maxI];
}
else
{
minI = Mathf.Min(lastSelectedFolderIndex, thisFolderIndex, selectionMinIndex);
maxI = Mathf.Max(lastSelectedFolderIndex, thisFolderIndex, selectionMaxIndex);
selectionMinFolder = visibleFolders[Mathf.Min(minI, selectionMinIndex)];
selectionMaxFolder = visibleFolders[Mathf.Max(maxI, selectionMaxIndex)];
}
lastSelectedFolder = visibleFolders[thisFolderIndex];
for (int i = minI; i <= maxI; i++)
{
if (!selectedFolders.Contains(visibleFolders[i]))
selectedFolders.Add(visibleFolders[i]);
}
}
}
void UpdateFoldoutStates(string folder, bool foldout)
{
//---Add this folder to the foldoutStates if it's not already added---//
if (!foldoutStates.ContainsKey(folder))
foldoutStates.Add(folder, foldout);
//---Get the subfolders and update those too---
string[] subfolders = AssetDatabase.GetSubFolders(folder);
foreach (string subfolder in subfolders)
{
UpdateFoldoutStates(subfolder, false);
}
}
void DrawAllSubFolders(string folder, int depth, float width)
{
//---If searching, check this folder is in the search results---//
bool inSearch = false;
foreach (string f in searchFolders)
{
if (f.Contains(folder))
{
inSearch = true;
break;
}
}
if (!inSearch && doSearch && depth > 0)
return;
visibleFolders.Add(folder);
//---Get display name and folder icon---//
string[] split = folder.Split('/');
string displayName = split[split.Length - 1];
displayName = " " + displayName;
GUIContent folderGuiContent;
if (!foldoutStates.ContainsKey(folder))
UpdateFoldoutStates(folder, false);
if (EditorGUIUtility.isProSkin || (selectedFolders.Contains(folder) && assetListFocused))
folderGuiContent = new GUIContent(displayName, foldoutStates[folder] ? folderIcons[1] : folderIcons[0]);
else
folderGuiContent = new GUIContent(displayName, foldoutStates[folder] ? folderIcons[3] : folderIcons[2]);
//---Use bold font for root "Assets" folder---//
if (depth == 0)
{
foldoutStyle.fontStyle = FontStyle.Bold;
foldoutStyleSelected.fontStyle = FontStyle.Bold;
}
else
{
foldoutStyle.fontStyle = FontStyle.Normal;
foldoutStyleSelected.fontStyle = FontStyle.Normal;
}
//---Get rect for this folder---//
Rect r = GUILayoutUtility.GetRect(folderGuiContent, GUI.skin.label);
r.position += new Vector2(15 * depth, 0);
r.yMin -= 1; r.yMax += 1;
//---Draw selection texture if folder is selected---//
if (selectedFolders.Contains(folder))
{
Rect selectRect = new Rect(r);
selectRect.position = new Vector2(0, r.position.y);
selectRect.width = width;
GUI.DrawTexture(selectRect, assetListFocused ? selectionTextures[0] : selectionTextures[1]);
if (window)
window.Repaint();
}
//---Get subfolders---//
string[] subfolders = AssetDatabase.GetSubFolders(folder);
if (subfolders.Length > 0)
{
//---Create clickArea rects---//
//There are two click areas, to the left and right of the foldout arrow button
Rect clickArea = new Rect(r);
Rect clickAreaLeft = new Rect(r);
clickArea.position += new Vector2(15, 0);
clickArea.width -= 15;
clickAreaLeft.width = 15 * depth;
clickAreaLeft.position = new Vector2(0, clickAreaLeft.position.y);
r.width = 15;
//---Check if either clickArea is clicked---//
if (GUI.Button(clickArea, "", GUIStyle.none) || GUI.Button(clickAreaLeft, "", GUIStyle.none))
{
selectFolder = folder;
window.assetGrid.assetGridFocused = false;
}
//---Draw the foldouts---//
//Store the original states before drawing so a change check can be done
bool chk = foldoutStates[folder];
foldoutStates[folder] = EditorGUI.Foldout(r, foldoutStates[folder], folderGuiContent, (selectedFolders.Contains(folder) && assetListFocused) ? foldoutStyleSelected : foldoutStyle);
//---If foldoutStates have changed---//
if (foldoutStates[folder] != chk)
{
//---Set focus true---//
assetListFocused = true;
GUI.FocusControl(null);
//---If alt key pressed, set all child folder states to match parent---//
if (Event.current.alt)
SetAllFoldoutChildren(folder, foldoutStates[folder]);
}
//---If foldout state is open---//
if (foldoutStates[folder])
{
//---Draw the sub folders (recursive)---
foreach (string subfolder in subfolders)
{
DrawAllSubFolders(subfolder, depth + 1, width);
}
}
}
else
{
//---If no subfolders, then draw a button (no style, i.e. clickable label) instead of a foldout---//
r.position += new Vector2(12, 0);
GUIStyle l = new GUIStyle(GUI.skin.label);
if (EditorGUIUtility.isProSkin)
l.normal.textColor = new Color32(192, 192, 192, 255);
else
l.normal.textColor = (selectedFolders.Contains(folder) && assetListFocused) ? Color.white : Color.black;
l.hover.textColor = l.normal.textColor;
l.active.textColor = l.normal.textColor;
Rect clickAreaLeft = new Rect(r);
clickAreaLeft.width = 15 * (depth + 1) + 4;
clickAreaLeft.position = new Vector2(0, clickAreaLeft.position.y);
if (GUI.Button(r, folderGuiContent, l) || GUI.Button(clickAreaLeft, "", GUIStyle.none))
{
selectFolder = folder;
window.assetGrid.assetGridFocused = false;
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 24f69c03ee5a76f4e8aae24472f18a45
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: