-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
using Virtuesky.FolderIcon.Editor; | ||
using VirtueSky.UtilsEditor; | ||
|
||
namespace VirtueSky.ControlPanel.Editor | ||
{ | ||
public class CPFolderIconDrawer | ||
{ | ||
private static UnityEditor.Editor _editor; | ||
private static FolderIconSettings _settings; | ||
|
||
public static void OnEnable() | ||
{ | ||
Init(); | ||
} | ||
|
||
private static void Init() | ||
{ | ||
if (_editor != null) | ||
{ | ||
_editor = null; | ||
} | ||
|
||
_settings = CreateAsset.GetScriptableAsset<FolderIconSettings>(); | ||
_editor = UnityEditor.Editor.CreateEditor(_settings); | ||
} | ||
|
||
public static void OnDrawFolderIcon() | ||
{ | ||
GUILayout.Space(10); | ||
GUILayout.BeginVertical(); | ||
GUILayout.Label("FOLDER ICON", EditorStyles.boldLabel); | ||
GUILayout.Space(10); | ||
if (_settings == null) | ||
{ | ||
if (GUILayout.Button("Create FolderIconSetting")) | ||
{ | ||
_settings = CreateAsset.CreateAndGetScriptableAsset<FolderIconSettings>( | ||
"Assets/_Sunflower/Editor/FolderIcon"); | ||
Init(); | ||
} | ||
} | ||
else | ||
{ | ||
if (_editor == null) | ||
{ | ||
EditorGUILayout.HelpBox("Couldn't create the settings editor.", | ||
MessageType.Error); | ||
return; | ||
} | ||
else | ||
{ | ||
_editor.OnInspectorGUI(); | ||
GUILayout.Space(10); | ||
if (_settings.customIcon) | ||
{ | ||
if (GUILayout.Button("Import texture icon folder")) | ||
{ | ||
AssetDatabase.ImportPackage( | ||
FileExtension.GetPathInCurrentEnvironent( | ||
"Module/FolderIcon/Editor/PackageIcon/icon_folder.unitypackage"), false); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
GUILayout.EndVertical(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
{ | ||
"name": "Wolf.UnityCommon.ControlPanel.Editor", | ||
"rootNamespace": "", | ||
"references": [ | ||
"GUID:8579ab42c9ab63d4bac5fb07bd390b46", | ||
"GUID:b1979aef4cc42ae46af23ce2c4c109cc", | ||
"GUID:324caed91501a9c47a04ebfd87b68794", | ||
"GUID:32dbaa332e571bf429b7de517f75f074", | ||
"GUID:0b6289df6f84a6f4b982ff72d23e0273", | ||
"GUID:49674d15b25185649b7ec8ac5d378747", | ||
"GUID:fca7ec166e04dc948b624a983315e2c9", | ||
"GUID:1d60d62a565144e418b3d9c8acc8eb80", | ||
"GUID:fcc03584b8436214db637bda56107579", | ||
"GUID:37f16d35c05c6f34eacb567043cec159", | ||
"GUID:6cd5a82756aabbb4dae8f59b2773a270", | ||
"GUID:b59f3d97c7580944baac8dafbd217904", | ||
"GUID:343a8c0b839a66c43afaf273c5e29583", | ||
"GUID:d25c81a6e03d11c4fb58d263c8aaea84" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
"name": "Wolf.UnityCommon.ControlPanel.Editor", | ||
"rootNamespace": "", | ||
"references": [ | ||
"GUID:8579ab42c9ab63d4bac5fb07bd390b46", | ||
"GUID:b1979aef4cc42ae46af23ce2c4c109cc", | ||
"GUID:324caed91501a9c47a04ebfd87b68794", | ||
"GUID:32dbaa332e571bf429b7de517f75f074", | ||
"GUID:0b6289df6f84a6f4b982ff72d23e0273", | ||
"GUID:49674d15b25185649b7ec8ac5d378747", | ||
"GUID:fca7ec166e04dc948b624a983315e2c9", | ||
"GUID:1d60d62a565144e418b3d9c8acc8eb80", | ||
"GUID:fcc03584b8436214db637bda56107579", | ||
"GUID:37f16d35c05c6f34eacb567043cec159", | ||
"GUID:6cd5a82756aabbb4dae8f59b2773a270", | ||
"GUID:b59f3d97c7580944baac8dafbd217904", | ||
"GUID:343a8c0b839a66c43afaf273c5e29583", | ||
"GUID:d25c81a6e03d11c4fb58d263c8aaea84", | ||
"GUID:877be62fd20bbdb489dd86ee21cee87d" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Virtuesky.FolderIcon.Editor | ||
{ | ||
[InitializeOnLoad] | ||
public class CustomFolder | ||
{ | ||
static CustomFolder() | ||
{ | ||
IconDictionaryCreator.BuildDictionary(); | ||
EditorApplication.projectWindowItemOnGUI += DrawFolderIcon; | ||
} | ||
|
||
static void DrawFolderIcon(string guid, Rect rect) | ||
{ | ||
var path = AssetDatabase.GUIDToAssetPath(guid); | ||
var iconDictionary = IconDictionaryCreator.IconDictionary; | ||
|
||
if (path == "" || | ||
Event.current.type != EventType.Repaint || | ||
!File.GetAttributes(path).HasFlag(FileAttributes.Directory) || | ||
!iconDictionary.ContainsKey(Path.GetFileName(path))) | ||
{ | ||
return; | ||
} | ||
|
||
Rect imageRect; | ||
|
||
if (rect.height > 20) | ||
{ | ||
imageRect = new Rect(rect.x - 1, rect.y - 1, rect.width + 2, rect.width + 2); | ||
} | ||
else if (rect.x > 20) | ||
{ | ||
imageRect = new Rect(rect.x - 1, rect.y - 1, rect.height + 2, rect.height + 2); | ||
} | ||
else | ||
{ | ||
imageRect = new Rect(rect.x + 2, rect.y - 1, rect.height + 2, rect.height + 2); | ||
} | ||
|
||
var texture = IconDictionaryCreator.IconDictionary[Path.GetFileName(path)]; | ||
if (texture == null) | ||
{ | ||
return; | ||
} | ||
|
||
GUI.DrawTexture(imageRect, texture); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using VirtueSky.Inspector; | ||
|
||
namespace Virtuesky.FolderIcon.Editor | ||
{ | ||
[HideMonoScript] | ||
public class FolderIconSettings : ScriptableObject | ||
{ | ||
public bool setupIconDefault; | ||
public bool customIcon; | ||
|
||
[ShowIf(nameof(customIcon)), TableList] | ||
public List<FolderIconData> folderIconDatas; | ||
|
||
public void OnValidate() | ||
{ | ||
IconDictionaryCreator.BuildDictionary(); | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class FolderIconData | ||
{ | ||
public Texture2D icon; | ||
public string folderName; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using VirtueSky.UtilsEditor; | ||
|
||
namespace Virtuesky.FolderIcon.Editor | ||
{ | ||
public class IconDictionaryCreator : AssetPostprocessor | ||
{ | ||
private const string AssetsPath = "/Module/FolderIcon/Icons"; | ||
internal static Dictionary<string, Texture> IconDictionary; | ||
|
||
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, | ||
string[] movedAssets, string[] movedFromAssetPaths) | ||
{ | ||
if (!ContainsIconAsset(importedAssets) && | ||
!ContainsIconAsset(deletedAssets) && | ||
!ContainsIconAsset(movedAssets) && | ||
!ContainsIconAsset(movedFromAssetPaths)) | ||
{ | ||
return; | ||
} | ||
|
||
BuildDictionary(); | ||
} | ||
|
||
private static bool ContainsIconAsset(string[] assets) | ||
{ | ||
foreach (string str in assets) | ||
{ | ||
if (ReplaceSeparatorChar(Path.GetDirectoryName(str)) == | ||
FileExtension.GetPathInCurrentEnvironent(AssetsPath)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static string ReplaceSeparatorChar(string path) | ||
{ | ||
return path.Replace("\\", "/"); | ||
} | ||
|
||
internal static void BuildDictionary() | ||
{ | ||
var dictionary = new Dictionary<string, Texture>(); | ||
var folderIconSettings = CreateAsset.GetScriptableAsset<FolderIconSettings>(); | ||
if (folderIconSettings != null) | ||
{ | ||
if (folderIconSettings.setupIconDefault) | ||
{ | ||
var dir = new DirectoryInfo(FileExtension.GetPathInCurrentEnvironent(AssetsPath)); | ||
FileInfo[] info = dir.GetFiles("*.png"); | ||
foreach (FileInfo f in info) | ||
{ | ||
var texture = | ||
(Texture)AssetDatabase.LoadAssetAtPath( | ||
FileExtension.GetPathInCurrentEnvironent($"{AssetsPath}/{f.Name}"), | ||
typeof(Texture2D)); | ||
dictionary.Add(Path.GetFileNameWithoutExtension(f.Name), texture); | ||
} | ||
} | ||
|
||
if (folderIconSettings.customIcon) | ||
{ | ||
foreach (var folderIconData in folderIconSettings.folderIconDatas) | ||
{ | ||
if (folderIconData == null) continue; | ||
if (folderIconData.icon == null || folderIconData.folderName == null) continue; | ||
dictionary.TryAdd(folderIconData.folderName, folderIconData.icon); | ||
} | ||
} | ||
} | ||
|
||
IconDictionary = dictionary; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.