Initial commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FolderIcons
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains all constant data, values and colours FolderIcon requires
|
||||
/// </summary>
|
||||
internal static class FolderIconConstants
|
||||
{
|
||||
public static readonly string ASSET_DEFAULT_PATH = Application.dataPath;
|
||||
|
||||
// Settings
|
||||
public const string FOLDER_TEXTURE_PATH = "Assets/ColouredFolders/Folders";
|
||||
public const string ICONS_TEXTURE_PATH = "Assets/ColouredFolders/Icons";
|
||||
|
||||
public const string PREF_FOLDER = "FolderPlus_ShowCustomFolders";
|
||||
public const string PREF_OVERLAY = "FolderPlus_ShowCustomIcons";
|
||||
|
||||
// GUI
|
||||
public const float MAX_TREE_WIDTH = 118f;
|
||||
public const float MAX_PROJECT_WIDTH = 96f;
|
||||
|
||||
public const float MAX_TREE_HEIGHT = 16f;
|
||||
public const float MAX_PROJECT_HEIGHT = 110f;
|
||||
|
||||
// Colours
|
||||
public static readonly Color SelectedColor = new Color (0.235f, 0.360f, 0.580f);
|
||||
public static Color BackgroundColour = EditorGUIUtility.isProSkin
|
||||
? new Color32 (51, 51, 51, 255)
|
||||
: new Color32 (190, 190, 190, 255);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb255ac2e3e747b4dbfb65d13738c9c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,87 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Linq;
|
||||
|
||||
namespace FolderIcons
|
||||
{
|
||||
/// <summary>
|
||||
/// GUI Methods for Folder Icons.
|
||||
/// </summary>
|
||||
public static class FolderIconGUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Draw the folder preview
|
||||
/// </summary>
|
||||
/// <param name="rect">Rect to draw preview</param>
|
||||
/// <param name="folder">The folder texture</param>
|
||||
/// <param name="overlay">The overlay texture</param>
|
||||
public static void DrawFolderPreview(Rect rect, Texture folder, Texture overlay)
|
||||
{
|
||||
if (folder == null && overlay == null)
|
||||
return;
|
||||
|
||||
if (folder != null)
|
||||
GUI.DrawTexture (rect, folder, ScaleMode.ScaleToFit);
|
||||
|
||||
//Half size of overlay, and reposition to center
|
||||
rect.size *= 0.5f;
|
||||
rect.position += rect.size * 0.5f;
|
||||
|
||||
if (overlay != null)
|
||||
GUI.DrawTexture (rect, overlay, ScaleMode.ScaleToFit);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw the folder texture and background rect if required
|
||||
/// </summary>
|
||||
/// <param name="rect">Folder rect</param>
|
||||
/// <param name="folder">Folder texture</param>
|
||||
/// <param name="guid">The guid of the project fodler</param>
|
||||
public static void DrawFolderTexture(Rect rect, Texture folder, string guid)
|
||||
{
|
||||
if (folder == null)
|
||||
return;
|
||||
|
||||
Color rectCol = Selection.assetGUIDs.Contains (guid)
|
||||
? FolderIconConstants.SelectedColor
|
||||
: FolderIconConstants.BackgroundColour;
|
||||
|
||||
EditorGUI.DrawRect (rect, rectCol);
|
||||
GUI.DrawTexture (rect, folder, ScaleMode.ScaleAndCrop);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw the folder overlay texture, given the folder rect
|
||||
/// </summary>
|
||||
/// <param name="rect">Original rect of the folder</param>
|
||||
/// <param name="overlay">Overlay Texture</param>
|
||||
public static void DrawOverlayTexture(Rect rect, Texture overlay)
|
||||
{
|
||||
if (overlay == null)
|
||||
return;
|
||||
|
||||
rect.size *= 0.5f;
|
||||
rect.position += rect.size * 0.5f;
|
||||
|
||||
GUI.DrawTexture (rect, overlay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the current rect is the side view of folders
|
||||
/// </summary>
|
||||
/// <param name="rect">Current rect</param>
|
||||
public static bool IsSideView(Rect rect)
|
||||
{
|
||||
return rect.x == 44;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the current rect is in tree view
|
||||
/// </summary>
|
||||
/// <param name="rect">Current rect</param>
|
||||
public static bool IsTreeView(Rect rect)
|
||||
{
|
||||
return rect.width > rect.height;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 335bc32bc652d7f4d99cd7dae7212b4a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace FolderIcons
|
||||
{
|
||||
[CreateAssetMenu (fileName = "Folder Icon Manager", menuName = "Scriptables/Others/Folder Manager")]
|
||||
public class FolderIconSettings : ScriptableObject
|
||||
{
|
||||
[Serializable]
|
||||
public class FolderIcon
|
||||
{
|
||||
public DefaultAsset folder;
|
||||
|
||||
public Texture2D folderIcon;
|
||||
public Texture2D overlayIcon;
|
||||
}
|
||||
|
||||
//Global Settings
|
||||
public bool showOverlay = true;
|
||||
public bool showCustomFolder = true;
|
||||
|
||||
public FolderIcon[] icons;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0be0684bc0644274383ab176323f4709
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,444 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using System.IO;
|
||||
|
||||
namespace FolderIcons
|
||||
{
|
||||
[CustomEditor (typeof (FolderIconSettings))]
|
||||
internal class FolderIconSettingsEditor : Editor
|
||||
{
|
||||
// References
|
||||
private FolderIconSettings settings;
|
||||
private SerializedProperty serializedIcons;
|
||||
|
||||
// Settings
|
||||
private bool showCustomFolders;
|
||||
private bool showCustomOverlay;
|
||||
|
||||
private ReorderableList iconList;
|
||||
|
||||
// Texture
|
||||
private Texture2D selectedTexture = null;
|
||||
private Texture2D previewTexture = null;
|
||||
|
||||
private GUIContent previewContent = new GUIContent ();
|
||||
private RenderTexture previewRender;
|
||||
|
||||
private Color replacementColour = Color.gray;
|
||||
|
||||
// Texture Save Settings
|
||||
private string textureName = "New Texture";
|
||||
private string savePath;
|
||||
|
||||
private int heightIndex;
|
||||
|
||||
// Sizing
|
||||
private const float MAX_LABEL_WIDTH = 90f;
|
||||
private const float MAX_FIELD_WIDTH = 150f;
|
||||
|
||||
private const float PROPERTY_HEIGHT = 19f;
|
||||
private const float PROPERTY_PADDING = 4f;
|
||||
private const float SETTINGS_PADDING = 1F;
|
||||
|
||||
// Styling
|
||||
private GUIStyle elementStyle;
|
||||
private GUIStyle propertyStyle;
|
||||
private GUIStyle previewStyle;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
settings = target as FolderIconSettings;
|
||||
serializedIcons = serializedObject.FindProperty ("icons");
|
||||
|
||||
showCustomFolders = settings.showCustomFolder;
|
||||
showCustomOverlay = settings.showOverlay;
|
||||
|
||||
if (iconList == null)
|
||||
{
|
||||
iconList = new ReorderableList (serializedObject, serializedIcons)
|
||||
{
|
||||
drawHeaderCallback = OnHeaderDraw,
|
||||
|
||||
drawElementCallback = OnElementDraw,
|
||||
drawElementBackgroundCallback = DrawElementBackground,
|
||||
|
||||
elementHeightCallback = GetPropertyHeight,
|
||||
|
||||
showDefaultBackground = false,
|
||||
};
|
||||
}
|
||||
|
||||
savePath = Application.dataPath;
|
||||
|
||||
if (selectedTexture != null)
|
||||
UpdatePreview ();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
ClearPreviewData ();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//Create styles
|
||||
if (previewStyle == null)
|
||||
{
|
||||
previewStyle = new GUIStyle (EditorStyles.label)
|
||||
{
|
||||
fixedHeight = 64,
|
||||
//fixedWidth = 64,
|
||||
//stretchWidth = false,
|
||||
alignment = TextAnchor.MiddleCenter
|
||||
};
|
||||
|
||||
elementStyle = new GUIStyle (GUI.skin.box)
|
||||
{
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// Draw Settings
|
||||
EditorGUILayout.LabelField ("Settings", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUI.BeginChangeCheck ();
|
||||
{
|
||||
showCustomFolders = EditorGUILayout.ToggleLeft ("Show Folder Textures", showCustomFolders);
|
||||
showCustomOverlay = EditorGUILayout.ToggleLeft ("Show Overlay Textures", showCustomOverlay);
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck ())
|
||||
{
|
||||
ApplySettings ();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space (16f);
|
||||
|
||||
EditorGUI.BeginChangeCheck ();
|
||||
iconList.DoLayoutList ();
|
||||
if (EditorGUI.EndChangeCheck ())
|
||||
serializedObject.ApplyModifiedProperties ();
|
||||
|
||||
DrawTexturePreview ();
|
||||
|
||||
EditorGUI.BeginDisabledGroup (previewTexture == null);
|
||||
{
|
||||
EditorGUI.BeginChangeCheck ();
|
||||
{
|
||||
replacementColour = EditorGUILayout.ColorField (new GUIContent ("Replacement Colour"), replacementColour);
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck ())
|
||||
SetPreviewColour ();
|
||||
|
||||
DrawTextureSaving ();
|
||||
}
|
||||
EditorGUI.EndDisabledGroup ();
|
||||
}
|
||||
|
||||
private void ApplySettings()
|
||||
{
|
||||
FolderIconsReplacer.showFolder = settings.showCustomFolder = showCustomFolders;
|
||||
FolderIconsReplacer.showOverlay = settings.showOverlay = showCustomOverlay;
|
||||
}
|
||||
|
||||
#region Reorderable Array Draw
|
||||
|
||||
private void OnHeaderDraw(Rect rect)
|
||||
{
|
||||
rect.y += 5f;
|
||||
rect.x -= 6f;
|
||||
rect.width += 12f;
|
||||
|
||||
Handles.BeginGUI ();
|
||||
Handles.DrawSolidRectangleWithOutline (rect,
|
||||
new Color (0.15f, 0.15f, 0.15f, 1f),
|
||||
new Color (0.15f, 0.15f, 0.15f, 1f));
|
||||
Handles.EndGUI ();
|
||||
|
||||
EditorGUI.LabelField (rect, "Folders", EditorStyles.boldLabel);
|
||||
|
||||
}
|
||||
|
||||
private void OnElementDraw( Rect rect, int index, bool isActive, bool isFocused)
|
||||
{
|
||||
SerializedProperty property = serializedIcons.GetArrayElementAtIndex (index);
|
||||
|
||||
float fullWidth = rect.width;
|
||||
|
||||
// Set sizes for correct draw
|
||||
float originalLabelWidth = EditorGUIUtility.labelWidth;
|
||||
float rectWidth = MAX_LABEL_WIDTH + MAX_FIELD_WIDTH;
|
||||
EditorGUIUtility.labelWidth = Mathf.Min(EditorGUIUtility.labelWidth, MAX_LABEL_WIDTH);
|
||||
rect.width = Mathf.Min(rect.width, rectWidth);
|
||||
|
||||
//Draw property and settings in a line
|
||||
DrawPropertyNoDepth (rect, property);
|
||||
|
||||
// ==========================
|
||||
// Draw Icon Example
|
||||
// ==========================
|
||||
rect.x += rect.width;
|
||||
rect.width = fullWidth - rect.width;
|
||||
|
||||
// References
|
||||
SerializedProperty folderTexture = property.FindPropertyRelative ("folderIcon");
|
||||
SerializedProperty overlayTexture = property.FindPropertyRelative ("overlayIcon");
|
||||
SerializedProperty overlayOffset = property.FindPropertyRelative ("overlayOffset");
|
||||
|
||||
// Object checks
|
||||
Object folderObject = folderTexture.objectReferenceValue;
|
||||
Object overlayObject = overlayTexture.objectReferenceValue;
|
||||
|
||||
FolderIconGUI.DrawFolderPreview (rect, folderObject as Texture, overlayObject as Texture);
|
||||
|
||||
// Revert width modification
|
||||
EditorGUIUtility.labelWidth = originalLabelWidth;
|
||||
}
|
||||
|
||||
private void DrawPropertyNoDepth(Rect rect, SerializedProperty property)
|
||||
{
|
||||
rect.width++;
|
||||
Handles.BeginGUI ();
|
||||
Handles.DrawSolidRectangleWithOutline (rect, Color.clear, new Color (0.15f, 0.15f, 0.15f, 1f));
|
||||
Handles.EndGUI ();
|
||||
|
||||
rect.x++;
|
||||
rect.width -= 3;
|
||||
rect.y += PROPERTY_PADDING;
|
||||
rect.height = PROPERTY_HEIGHT;
|
||||
|
||||
SerializedProperty copy = property.Copy ();
|
||||
bool enterChildren = true;
|
||||
|
||||
while(copy.Next(enterChildren))
|
||||
{
|
||||
if (SerializedProperty.EqualContents (copy, property.GetEndProperty ()))
|
||||
break;
|
||||
|
||||
EditorGUI.PropertyField (rect, copy, false);
|
||||
rect.y += PROPERTY_HEIGHT + PROPERTY_PADDING;
|
||||
|
||||
enterChildren = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawElementBackground(Rect rect, int index, bool isActive, bool isFocused)
|
||||
{
|
||||
EditorGUI.LabelField (rect, "", elementStyle);
|
||||
|
||||
Color fill = (isFocused) ? FolderIconConstants.SelectedColor : Color.clear;
|
||||
|
||||
Handles.BeginGUI ();
|
||||
Handles.DrawSolidRectangleWithOutline (rect, fill, new Color(0.15f, 0.15f, 0.15f, 1f));
|
||||
Handles.EndGUI ();
|
||||
}
|
||||
|
||||
|
||||
// ========================
|
||||
//
|
||||
// ========================
|
||||
private int GetPropertyCount(SerializedProperty property)
|
||||
{
|
||||
return property.CountInProperty () - 1;
|
||||
}
|
||||
|
||||
private float GetPropertyHeight(SerializedProperty property)
|
||||
{
|
||||
if (heightIndex == 0)
|
||||
heightIndex = property.CountInProperty ();
|
||||
|
||||
// return (PROPERTY_HEIGHT + PROPERTY_PADDING) * (heightIndex-1) + PROPERTY_PADDING;
|
||||
|
||||
//Property count returning wrong, so just supplying 3 for now
|
||||
//TODO: Investigate GetPropertyCount and find issue with invalid value
|
||||
return (PROPERTY_HEIGHT + PROPERTY_PADDING) * (3) + PROPERTY_PADDING;
|
||||
}
|
||||
|
||||
private float GetPropertyHeight(int index)
|
||||
{
|
||||
return GetPropertyHeight (serializedIcons.GetArrayElementAtIndex (index));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Texture Preview/Creation
|
||||
|
||||
/// <summary>
|
||||
/// Draw the preview for the texture
|
||||
/// </summary>
|
||||
private void DrawTexturePreview()
|
||||
{
|
||||
EditorGUILayout.LabelField ("Texture Colour Replacement", EditorStyles.boldLabel);
|
||||
|
||||
// Draw selection
|
||||
EditorGUI.BeginChangeCheck ();
|
||||
{
|
||||
|
||||
// Headers
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
EditorGUILayout.LabelField ("Original Texture");
|
||||
EditorGUILayout.LabelField ("Modified Texture");
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
|
||||
// Texture -- Preview
|
||||
EditorGUILayout.BeginHorizontal ();
|
||||
{
|
||||
selectedTexture = EditorGUILayout.ObjectField ( selectedTexture, typeof (Texture2D),
|
||||
false, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true), GUILayout.Width(64f)) as Texture2D;
|
||||
|
||||
EditorGUILayout.LabelField (previewContent, previewStyle, GUILayout.Height(64));
|
||||
}
|
||||
EditorGUILayout.EndHorizontal ();
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck ())
|
||||
{
|
||||
if (selectedTexture == null)
|
||||
{
|
||||
ClearPreviewData ();
|
||||
previewTexture = null;
|
||||
return;
|
||||
}
|
||||
|
||||
UpdatePreview ();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display settings for saving the modified texture
|
||||
/// </summary>
|
||||
private void DrawTextureSaving()
|
||||
{
|
||||
EditorGUILayout.LabelField ("Save Created Texture", EditorStyles.boldLabel);
|
||||
|
||||
// Texture Name
|
||||
GUILayout.BeginHorizontal ();
|
||||
{
|
||||
textureName = EditorGUILayout.TextField ("Texture Name", textureName);
|
||||
|
||||
EditorGUI.BeginDisabledGroup (true);
|
||||
GUILayout.TextField (".png", GUILayout.Width(40f));
|
||||
EditorGUI.EndDisabledGroup ();
|
||||
}
|
||||
GUILayout.EndHorizontal ();
|
||||
|
||||
// Save Path
|
||||
GUILayout.BeginHorizontal ();
|
||||
{
|
||||
savePath = EditorGUILayout.TextField ("Save Path", savePath);
|
||||
|
||||
if (GUILayout.Button ("Select", GUILayout.MaxWidth(80f)))
|
||||
{
|
||||
savePath = EditorUtility.OpenFolderPanel ("Texture Save Path", "Assets", "");
|
||||
GUIUtility.ExitGUI ();
|
||||
}
|
||||
|
||||
}
|
||||
GUILayout.EndHorizontal ();
|
||||
|
||||
if (GUILayout.Button ("Save Texture"))
|
||||
{
|
||||
string fullPath = $"{savePath}/{textureName}.png";
|
||||
SaveTextureAsPNG (previewTexture, fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply colour to preview texture
|
||||
/// </summary>
|
||||
private void SetPreviewColour()
|
||||
{
|
||||
for (int x = 0; x < previewTexture.width; x++)
|
||||
{
|
||||
for (int y = 0; y < previewTexture.height; y++)
|
||||
{
|
||||
Color oldCol = previewTexture.GetPixel (x, y);
|
||||
Color newCol = replacementColour;
|
||||
newCol.a = oldCol.a;
|
||||
|
||||
previewTexture.SetPixel (x, y, newCol);
|
||||
}
|
||||
}
|
||||
|
||||
previewTexture.Apply ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save the preview texture at the given path
|
||||
/// </summary>
|
||||
/// <param name="texture">The preview texture</param>
|
||||
/// <param name="path">The path to save the texture at</param>
|
||||
private void SaveTextureAsPNG(Texture2D texture, string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path) || !path.Contains("Assets"))
|
||||
{
|
||||
Debug.LogWarning ("Cannot save texture to invalid path.");
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] bytes = texture.EncodeToPNG ();
|
||||
File.WriteAllBytes (path, bytes);
|
||||
|
||||
AssetDatabase.Refresh ();
|
||||
|
||||
int localPathIndex = path.IndexOf ("Assets");
|
||||
path = path.Substring (localPathIndex, path.Length - localPathIndex);
|
||||
|
||||
TextureImporter importer = AssetImporter.GetAtPath (path) as TextureImporter;
|
||||
|
||||
importer.textureType = TextureImporterType.GUI;
|
||||
importer.isReadable = true;
|
||||
|
||||
AssetDatabase.ImportAsset (path);
|
||||
AssetDatabase.Refresh ();
|
||||
|
||||
//Texture2D textureAsset = AssetDatabase.LoadAssetAtPath<Texture2D> (path);
|
||||
//textureAsset.alphaIsTransparency = true;
|
||||
//textureAsset.Apply ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear preview render texture
|
||||
/// </summary>
|
||||
private void ClearPreviewData()
|
||||
{
|
||||
if (previewRender != null)
|
||||
previewRender.Release ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the preview with new texture information
|
||||
/// </summary>
|
||||
private void UpdatePreview()
|
||||
{
|
||||
ClearPreviewData ();
|
||||
|
||||
//No real point having a huge texture so limit the size for efficency sake
|
||||
int width = Mathf.Min (256, selectedTexture.width);
|
||||
int height = Mathf.Min (256, selectedTexture.height);
|
||||
|
||||
//Create a new render texture and preview
|
||||
previewRender = new RenderTexture (width, height, 16);
|
||||
previewTexture = new Texture2D (previewRender.width, previewRender.height)
|
||||
{
|
||||
alphaIsTransparency = true
|
||||
};
|
||||
previewContent.image = previewTexture;
|
||||
|
||||
Graphics.Blit (selectedTexture, previewRender);
|
||||
|
||||
// Get pixels from current render texture and apply
|
||||
previewTexture.ReadPixels (new Rect (0, 0, previewRender.width, previewRender.height), 0, 0);
|
||||
SetPreviewColour ();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0143459d5e876074faec6c800d875e79
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,139 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FolderIcons
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
internal static class FolderIconsReplacer
|
||||
{
|
||||
// References
|
||||
private static Object[] allFolderIcons;
|
||||
private static FolderIconSettings folderIcons;
|
||||
|
||||
public static bool showFolder;
|
||||
public static bool showOverlay;
|
||||
|
||||
private static readonly Color selectedColor = new Color (60f/255f, 92f/255f, 148f/255f);
|
||||
|
||||
static FolderIconsReplacer()
|
||||
{
|
||||
CheckPreferences ();
|
||||
|
||||
EditorApplication.projectWindowItemOnGUI -= ReplaceFolders;
|
||||
EditorApplication.projectWindowItemOnGUI += ReplaceFolders;
|
||||
}
|
||||
|
||||
private static void ReplaceFolders(string guid, Rect selectionRect)
|
||||
{
|
||||
// Does the folder asset exist at all?
|
||||
if (allFolderIcons == null)
|
||||
allFolderIcons = GetAllInstances<FolderIconSettings> ();
|
||||
|
||||
if (folderIcons == null)
|
||||
{
|
||||
if (allFolderIcons.Length > 0)
|
||||
folderIcons = allFolderIcons[0] as FolderIconSettings;
|
||||
}
|
||||
|
||||
if (folderIcons == null)
|
||||
return;
|
||||
|
||||
if (!folderIcons.showCustomFolder && !folderIcons.showOverlay)
|
||||
return;
|
||||
|
||||
string path = AssetDatabase.GUIDToAssetPath (guid);
|
||||
Object folderAsset = AssetDatabase.LoadAssetAtPath (path, typeof (DefaultAsset));
|
||||
|
||||
if (folderAsset == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < folderIcons.icons.Length; i++)
|
||||
{
|
||||
var icon = folderIcons.icons[i];
|
||||
|
||||
if (icon.folder != folderAsset)
|
||||
continue;
|
||||
|
||||
DrawTextures (selectionRect, icon, folderAsset, guid);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawTextures(Rect rect, FolderIconSettings.FolderIcon icon, Object folderAsset, string guid)
|
||||
{
|
||||
bool isTreeView = rect.width > rect.height;
|
||||
bool isSideView = FolderIconGUI.IsSideView (rect);
|
||||
|
||||
// Vertical Folder View
|
||||
if (isTreeView)
|
||||
{
|
||||
rect.width = rect.height = FolderIconConstants.MAX_TREE_HEIGHT;
|
||||
|
||||
//Add small offset for correct placement
|
||||
if (!isSideView)
|
||||
rect.x += 3f;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.height -= 14f;
|
||||
}
|
||||
|
||||
if (showFolder && icon.folderIcon)
|
||||
FolderIconGUI.DrawFolderTexture (rect, icon.folderIcon, guid);
|
||||
|
||||
if (showOverlay && icon.overlayIcon)
|
||||
FolderIconGUI.DrawOverlayTexture (rect, icon.overlayIcon);
|
||||
}
|
||||
|
||||
#region Initialize
|
||||
|
||||
private static void CheckPreferences()
|
||||
{
|
||||
string prefFolder = FolderIconConstants.FOLDER_TEXTURE_PATH;
|
||||
string prefIcon = FolderIconConstants.ICONS_TEXTURE_PATH;
|
||||
|
||||
if (!EditorPrefs.HasKey (prefFolder))
|
||||
EditorPrefs.SetBool (prefFolder, true);
|
||||
|
||||
if (!EditorPrefs.HasKey (prefIcon))
|
||||
EditorPrefs.SetBool (prefIcon, true);
|
||||
|
||||
showFolder = EditorPrefs.GetBool (prefFolder);
|
||||
showOverlay = EditorPrefs.GetBool (prefIcon);
|
||||
}
|
||||
|
||||
private static bool FindOrCreateFolder(string path, string folderCreateName)
|
||||
{
|
||||
if (AssetDatabase.IsValidFolder (path))
|
||||
return true;
|
||||
|
||||
string parentFolder = path.Substring (0, path.LastIndexOf ('/'));
|
||||
return AssetDatabase.CreateFolder(parentFolder, folderCreateName) != "";
|
||||
}
|
||||
|
||||
private static T[] GetAllInstances<T>() where T : Object
|
||||
{
|
||||
string[] guids = AssetDatabase.FindAssets ("t:" + typeof (T).Name);
|
||||
|
||||
T[] instances = new T[guids.Length];
|
||||
|
||||
//probably could get optimized
|
||||
for (int i = 0; i < guids.Length; i++)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath (guids[i]);
|
||||
instances[i] = AssetDatabase.LoadAssetAtPath<T> (path);
|
||||
}
|
||||
|
||||
|
||||
return instances;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea97ce8725f3d974f8357a162385fad1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user