1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// Cristian Pop - https://boxophobic.com/
using UnityEngine;
using UnityEditor;
namespace Boxophobic.StyledGUI
{
[CustomPropertyDrawer(typeof(StyledRangeOptions))]
public class StyledRangeOptionsAttributeDrawer : PropertyDrawer
{
StyledRangeOptions a;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
a = (StyledRangeOptions)attribute;
GUIStyle styleMid = new GUIStyle();
styleMid.alignment = TextAnchor.MiddleCenter;
styleMid.normal.textColor = Color.gray;
styleMid.fontSize = 7;
if (a.displayLabel.Length > 0)
{
EditorGUI.PropertyField(position, property, label, true);
GUILayout.Space(5);
}
GUILayout.BeginHorizontal();
GUILayout.Space(8);
property.floatValue = GUILayout.HorizontalSlider(property.floatValue, a.min, a.max);
property.floatValue = Mathf.Clamp(property.floatValue, a.min, a.max);
property.floatValue = Mathf.Round(property.floatValue * 1000f) / 1000f;
GUILayout.Space(8);
GUILayout.EndHorizontal();
#if UNITY_2019_3_OR_NEWER
GUILayout.Space(15);
#endif
GUILayout.BeginHorizontal();
int maxWidth = 20;
#if UNITY_2019_3_OR_NEWER
maxWidth = 28;
#endif
for (int i = 0; i < a.options.Length - 1; i++)
{
GUILayout.Label(a.options[i], styleMid, GUILayout.Width(maxWidth));
GUILayout.Label("", styleMid);
}
GUILayout.Label(a.options[a.options.Length - 1], styleMid, GUILayout.Width(maxWidth));
GUILayout.EndHorizontal();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
a = (StyledRangeOptions)attribute;
if (a.displayLabel.Length > 0)
{
return 18;
}
else
{
return -2;
}
}
}
}
|