A game about forced loneliness, made by TACStudios
1#if UNITY_EDITOR
2using System.IO;
3using UnityEditor;
4
5namespace UnityEngine.InputSystem.Editor
6{
7 internal static class GUIHelpers
8 {
9 public static class Styles
10 {
11 public static readonly GUIStyle lineSeparator = new GUIStyle().WithFixedHeight(1).WithMargin(new RectOffset(0, 0, 2, 2));
12 }
13
14 private const string kIconPath = "Packages/com.unity.inputsystem/InputSystem/Editor/Icons/";
15
16 public static void DrawLineSeparator(string label = null)
17 {
18 var hasLabel = !string.IsNullOrEmpty(label);
19 EditorGUILayout.BeginVertical();
20 var rect = GUILayoutUtility.GetRect(GUIContent.none, Styles.lineSeparator, GUILayout.ExpandWidth(true));
21 var labelRect = new Rect();
22 GUIContent labelContent = null;
23 if (hasLabel)
24 {
25 labelContent = new GUIContent(label);
26 labelRect = GUILayoutUtility.GetRect(labelContent, EditorStyles.miniLabel, GUILayout.ExpandWidth(true));
27 }
28 EditorGUILayout.EndVertical();
29
30 if (Event.current.type != EventType.Repaint)
31 return;
32
33 var orgColor = GUI.color;
34 var tintColor = EditorGUIUtility.isProSkin ? new Color(0.12f, 0.12f, 0.12f, 1.333f) : new Color(0.6f, 0.6f, 0.6f, 1.333f);
35 GUI.color = GUI.color * tintColor;
36 GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture);
37 GUI.color = orgColor;
38
39 if (hasLabel)
40 EditorGUI.LabelField(labelRect, labelContent, EditorStyles.miniLabel);
41 }
42
43 public static Texture2D LoadIcon(string name)
44 {
45 var skinPrefix = EditorGUIUtility.isProSkin ? "d_" : "";
46 var scale = Mathf.Clamp((int)EditorGUIUtility.pixelsPerPoint, 0, 4);
47 var scalePostFix = scale > 1 ? $"@{scale}x" : "";
48 if (name.IndexOfAny(Path.GetInvalidFileNameChars()) > -1)
49 name = string.Join("_", name.Split(Path.GetInvalidFileNameChars()));
50 var path = Path.Combine(kIconPath, skinPrefix + name + scalePostFix + ".png");
51 return AssetDatabase.LoadAssetAtPath<Texture2D>(path);
52 }
53
54 public static GUIStyle WithNormalBackground(this GUIStyle style, Texture2D background)
55 {
56 style.normal.background = background;
57 return style;
58 }
59
60 public static GUIStyle WithFontSize(this GUIStyle style, int fontSize)
61 {
62 style.fontSize = fontSize;
63 return style;
64 }
65
66 public static GUIStyle WithFontStyle(this GUIStyle style, FontStyle fontStyle)
67 {
68 style.fontStyle = fontStyle;
69 return style;
70 }
71
72 public static GUIStyle WithAlignment(this GUIStyle style, TextAnchor alignment)
73 {
74 style.alignment = alignment;
75 return style;
76 }
77
78 public static GUIStyle WithMargin(this GUIStyle style, RectOffset margin)
79 {
80 style.margin = margin;
81 return style;
82 }
83
84 public static GUIStyle WithBorder(this GUIStyle style, RectOffset border)
85 {
86 style.border = border;
87 return style;
88 }
89
90 public static GUIStyle WithPadding(this GUIStyle style, RectOffset padding)
91 {
92 style.padding = padding;
93 return style;
94 }
95
96 public static GUIStyle WithFixedWidth(this GUIStyle style, int fixedWidth)
97 {
98 style.fixedWidth = fixedWidth;
99 return style;
100 }
101
102 public static GUIStyle WithFixedHeight(this GUIStyle style, int fixedHeight)
103 {
104 style.fixedHeight = fixedHeight;
105 return style;
106 }
107
108 public static GUIStyle WithRichText(this GUIStyle style, bool richText = true)
109 {
110 style.richText = richText;
111 return style;
112 }
113
114 public static GUIStyle WithFont(this GUIStyle style, Font font)
115 {
116 style.font = font;
117 return style;
118 }
119
120 public static GUIStyle WithContentOffset(this GUIStyle style, Vector2 contentOffset)
121 {
122 style.contentOffset = contentOffset;
123 return style;
124 }
125
126 public static GUIStyle WithNormalTextColor(this GUIStyle style, Color textColor)
127 {
128 style.normal.textColor = textColor;
129 return style;
130 }
131 }
132}
133#endif // UNITY_EDITOR