Last active
July 26, 2021 15:22
-
-
Save ApprenticeGC/d705870125debd4e402d to your computer and use it in GitHub Desktop.
Unity editor project window folder icon modification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| using System.Text; | |
| using System.Text.RegularExpressions; | |
| using UnityEditor; | |
| using UnityEngine; | |
| [UnityEditor.InitializeOnLoad] | |
| public class ProjectIcons : Editor | |
| { | |
| static string basePath = "Assets/Unity Chan Run Run/Editor/Icons/"; | |
| static ProjectIcons() | |
| { | |
| EditorApplication.projectWindowItemOnGUI += ProjectIcons.MyCallback(); | |
| } | |
| static EditorApplication.ProjectWindowItemCallback MyCallback() | |
| { | |
| EditorApplication.ProjectWindowItemCallback myCallback = new EditorApplication.ProjectWindowItemCallback(IconGUI); | |
| return myCallback; | |
| } | |
| static void IconGUI(string s, Rect r) | |
| { | |
| Regex rootGameFolderPathRegex = new Regex(@"Assets/Unity Chan Run Run$"); | |
| string fileName = AssetDatabase.GUIDToAssetPath(s); | |
| MatchThenDraw(r, rootGameFolderPathRegex, fileName, Path.Combine(basePath, "game.png")); | |
| } | |
| static void MatchThenDraw(Rect r, Regex regexPattern, String fileName, String texturePath) | |
| { | |
| Match match = regexPattern.Match(fileName); | |
| if (match.Success) | |
| { | |
| r.width = r.height; | |
| Texture2D icon = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)); | |
| if (icon != null) | |
| { | |
| GUI.DrawTexture(r, icon); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| using System.Text; | |
| using System.Text.RegularExpressions; | |
| using UnityEditor; | |
| using UnityEngine; | |
| [UnityEditor.InitializeOnLoad] | |
| public class ProjectIcons : Editor | |
| { | |
| static string basePath = "Assets/Unity Chan Run Run/Editor/Icons/"; | |
| static ProjectIcons() | |
| { | |
| EditorApplication.projectWindowItemOnGUI += ProjectIcons.MyCallback(); | |
| } | |
| static EditorApplication.ProjectWindowItemCallback MyCallback() | |
| { | |
| EditorApplication.ProjectWindowItemCallback myCallback = new EditorApplication.ProjectWindowItemCallback(IconGUI); | |
| return myCallback; | |
| } | |
| static void IconGUI(string s, Rect r) | |
| { | |
| Regex rootGameFolderPathRegex = new Regex(@"Assets/Unity Chan Run Run$"); | |
| Regex editorFolderPathRegex = new Regex(@"Assets/Unity Chan Run Run[//a-zA-Z0-9]*/Editor$"); | |
| Regex resourcesFolderPathRegex = new Regex(@"Assets/Unity Chan Run Run[//a-zA-Z0-9]*/Resources$"); | |
| string fileName = AssetDatabase.GUIDToAssetPath(s); | |
| MatchThenDraw(r, rootGameFolderPathRegex, fileName, Path.Combine(basePath, "game.png")); | |
| MatchThenDraw(r, editorFolderPathRegex, fileName, Path.Combine(basePath, "editor.png")); | |
| MatchThenDraw(r, resourcesFolderPathRegex, fileName, Path.Combine(basePath, "resources.png")); | |
| } | |
| static void MatchThenDraw(Rect r, Regex regexPattern, string fileName, string texturePath) | |
| { | |
| Func<Rect, Rect> adjustedRect = new Func<Rect, Rect>(rect => | |
| { | |
| bool minimized = Mathf.Approximately(rect.height, 16.0f); | |
| if (minimized) | |
| { | |
| rect.width = r.height; | |
| } | |
| else | |
| { | |
| rect.height -= 16.0f; | |
| } | |
| return rect; | |
| }); | |
| Match match = regexPattern.Match(fileName); | |
| if (match.Success) | |
| { | |
| r = adjustedRect(r); | |
| Texture2D icon = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)); | |
| if (icon != null) | |
| { | |
| GUI.DrawTexture(r, icon); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment