using UnityEngine; #if UNITY_EDITOR using UnityEditor; namespace Jovian.InspectorTools.Internal { public static class RequiredUtil { private const float ICON_X_OFFSET = 15f; private const float ICON_SIZE = 18f; private static Color ErrorColor = new(1f, 0.5f, 0.5f, 1f); private static GUIContent errorIcon; private static GUIStyle errorStyle; public static void LayoutRequired(ref Rect position, string tooltip, bool indent = true) { if (indent) { position.x += ICON_SIZE; position.width -= ICON_SIZE; } } public static void DrawRequired(ref Rect position, string tooltip, bool indent = true) { if(errorIcon == null || errorStyle == null) { errorIcon = new GUIContent(EditorGUIUtility.IconContent("console.erroricon.sml").image); errorStyle = new GUIStyle(GUI.skin.label) { padding = new RectOffset(0, 0, 0, 0), imagePosition = ImagePosition.ImageOnly }; } errorIcon.tooltip = tooltip; Rect errorIconRect = new Rect(position.x - ICON_X_OFFSET, position.y + 1, ICON_SIZE, EditorGUIUtility.singleLineHeight); GUI.Label(errorIconRect, errorIcon, errorStyle); GUI.color = ErrorColor; if (indent) { position.x += ICON_SIZE; position.width -= ICON_SIZE; } } } } #endif