using UnityEngine; using UnityEditor; using System.Linq; namespace FolderIcons { /// /// GUI Methods for Folder Icons. /// public static class FolderIconGUI { /// /// Draw the folder preview /// /// Rect to draw preview /// The folder texture /// The overlay texture 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); } /// /// Draw the folder texture and background rect if required /// /// Folder rect /// Folder texture /// The guid of the project fodler 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); } /// /// Draw the folder overlay texture, given the folder rect /// /// Original rect of the folder /// Overlay Texture 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); } /// /// Check if the current rect is the side view of folders /// /// Current rect public static bool IsSideView(Rect rect) { return rect.x == 44; } /// /// Check if the current rect is in tree view /// /// Current rect public static bool IsTreeView(Rect rect) { return rect.width > rect.height; } } }