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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
namespace Coffee.UIEffects.Editors
{
/// <summary>
/// UIEffect editor.
/// </summary>
[CustomEditor(typeof(UIGradient))]
[CanEditMultipleObjects]
public class UIGradientEditor : Editor
{
private static readonly GUIContent k_TextVerticalOffset = new GUIContent("Vertical Offset");
private static readonly GUIContent k_TextHorizontalOffset = new GUIContent("Horizontal Offset");
private static readonly GUIContent k_TextOffset = new GUIContent("Offset");
private static readonly GUIContent k_TextLeft = new GUIContent("Left");
private static readonly GUIContent k_TextRight = new GUIContent("Right");
private static readonly GUIContent k_TextTop = new GUIContent("Top");
private static readonly GUIContent k_TextBottom = new GUIContent("Bottom");
private static readonly GUIContent k_TextColor1 = new GUIContent("Color 1");
private static readonly GUIContent k_TextColor2 = new GUIContent("Color 2");
private static readonly GUIContent k_TextDiagonalColor = new GUIContent("Diagonal Color");
SerializedProperty _spDirection;
SerializedProperty _spColor1;
SerializedProperty _spColor2;
SerializedProperty _spColor3;
SerializedProperty _spColor4;
SerializedProperty _spRotation;
SerializedProperty _spOffset1;
SerializedProperty _spOffset2;
SerializedProperty _spIgnoreAspectRatio;
SerializedProperty _spGradientStyle;
SerializedProperty _spColorSpace;
//################################
// Public/Protected Members.
//################################
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected void OnEnable()
{
_spIgnoreAspectRatio = serializedObject.FindProperty("m_IgnoreAspectRatio");
_spDirection = serializedObject.FindProperty("m_Direction");
_spColor1 = serializedObject.FindProperty("m_Color1");
_spColor2 = serializedObject.FindProperty("m_Color2");
_spColor3 = serializedObject.FindProperty("m_Color3");
_spColor4 = serializedObject.FindProperty("m_Color4");
_spRotation = serializedObject.FindProperty("m_Rotation");
_spOffset1 = serializedObject.FindProperty("m_Offset1");
_spOffset2 = serializedObject.FindProperty("m_Offset2");
_spGradientStyle = serializedObject.FindProperty("m_GradientStyle");
_spColorSpace = serializedObject.FindProperty("m_ColorSpace");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
//================
// Direction.
//================
EditorGUILayout.PropertyField(_spDirection);
//================
// Color.
//================
switch ((UIGradient.Direction) _spDirection.intValue)
{
case UIGradient.Direction.Horizontal:
EditorGUILayout.PropertyField(_spColor1, k_TextLeft);
EditorGUILayout.PropertyField(_spColor2, k_TextRight);
break;
case UIGradient.Direction.Vertical:
EditorGUILayout.PropertyField(_spColor1, k_TextTop);
EditorGUILayout.PropertyField(_spColor2, k_TextBottom);
break;
case UIGradient.Direction.Angle:
EditorGUILayout.PropertyField(_spColor1, k_TextColor1);
EditorGUILayout.PropertyField(_spColor2, k_TextColor2);
break;
case UIGradient.Direction.Diagonal:
Rect r = EditorGUILayout.GetControlRect(false, 34);
r = EditorGUI.PrefixLabel(r, k_TextDiagonalColor);
float w = r.width / 2;
EditorGUI.PropertyField(new Rect(r.x, r.y, w, 16), _spColor3, GUIContent.none);
EditorGUI.PropertyField(new Rect(r.x + w, r.y, w, 16), _spColor4, GUIContent.none);
EditorGUI.PropertyField(new Rect(r.x, r.y + 18, w, 16), _spColor1, GUIContent.none);
EditorGUI.PropertyField(new Rect(r.x + w, r.y + 18, w, 16), _spColor2, GUIContent.none);
break;
}
//================
// Angle.
//================
if ((int) UIGradient.Direction.Angle <= _spDirection.intValue)
{
EditorGUILayout.PropertyField(_spRotation);
}
//================
// Offset.
//================
if ((int) UIGradient.Direction.Diagonal == _spDirection.intValue)
{
EditorGUILayout.PropertyField(_spOffset1, k_TextVerticalOffset);
EditorGUILayout.PropertyField(_spOffset2, k_TextHorizontalOffset);
}
else
{
EditorGUILayout.PropertyField(_spOffset1, k_TextOffset);
}
//================
// Advanced options.
//================
EditorGUILayout.Space();
EditorGUILayout.LabelField("Advanced Options", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
{
//if ((target as UIGradient).targetGraphic is Text)
EditorGUILayout.PropertyField(_spGradientStyle);
EditorGUILayout.PropertyField(_spColorSpace);
EditorGUILayout.PropertyField(_spIgnoreAspectRatio);
}
EditorGUI.indentLevel--;
serializedObject.ApplyModifiedProperties();
}
}
}
|