// // Copyright (c) 2017 Anthony Marmont. All rights reserved. // Licensed for use under the Unity Asset Store EULA. See https://unity3d.com/legal/as_terms for full license information. // #if UNITY_EDITOR #pragma warning disable using System; using System.Collections.Generic; using UnityEngine; namespace AssetIcons.Editors { /// /// A collection of utility methods for drawing graphics with AssetIcons. /// public static class AssetIconsGUIUtility { /// /// Remaps a to conform with Unity's UI control positions. /// /// /// The repositioned over the original icon. /// /// The in which the item is drawn. /// The max size of the . public static Rect AreaToIconRect(Rect rect, float maxSize = 64.0f) { bool isSmall = IsIconSmall(rect); if (isSmall) { rect.width = rect.height; } else { rect.height = rect.width; #if UNITY_2019_3_OR_NEWER rect.width += 1.0f; #endif } if (rect.width <= maxSize && rect.height <= maxSize) { #if UNITY_5_5 if (isSmall) { rect = new Rect (rect.x + 3, rect.y, rect.width, rect.height); } #elif UNITY_5_6_OR_NEWER if (isSmall && !IsTreeView(rect)) { rect = new Rect(rect.x + 3, rect.y, rect.width, rect.height); } #endif } else { float offset = (rect.width - maxSize) * 0.5f; rect = new Rect(rect.x + offset, rect.y + offset, maxSize, maxSize); } return rect; } /// /// Determines if the should be drawn using a small icon. /// /// /// true if the icon is small; otherwise, false. /// /// The rect to check if it's small. private static bool IsIconSmall(Rect rect) { return rect.width > rect.height; } /// /// Determines if the is being drawn in Tree View. /// /// /// true if is the specified is in TreeView; otherwise, false. /// /// The used to check if it's being drawn in treeview. private static bool IsTreeView(Rect rect) { return (rect.x - 16) % 14 == 0; } } } #pragma warning restore #endif