Skip to content

Commit 152ca58

Browse files
committed
Add gradient support (in hacking way)
Change assembly info
1 parent 40bfff0 commit 152ca58

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

UInspectorPlus/Helpers.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ enum PropertyType {
2424
Color,
2525
Rect,
2626
Bounds,
27+
Gradient,
2728
Curve,
2829
String,
2930
Object,
@@ -68,6 +69,29 @@ public static class Helper {
6869
internal static readonly Dictionary<Type, PropertyType> propertyTypeMapper = new Dictionary<Type, PropertyType>();
6970
internal static readonly Dictionary<Type, HashSet<string>> blackListedTypes = new Dictionary<Type, HashSet<string>>();
7071
static double clickTime;
72+
73+
// Delegate hacks to access the internal methods
74+
internal static readonly Func<GUIContent, Rect, Gradient, Gradient> doGradientField = Delegate.CreateDelegate(
75+
typeof(Func<GUIContent, Rect, Gradient, Gradient>),
76+
typeof(EditorGUI).GetMethod(
77+
"GradientField",
78+
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static,
79+
null, CallingConventions.Any,
80+
new[] { typeof(GUIContent), typeof(Rect), typeof(Gradient) },
81+
null
82+
)
83+
) as Func<GUIContent, Rect, Gradient, Gradient>;
84+
85+
internal static readonly Func<GUIContent, Gradient, GUILayoutOption[], Gradient> doLayoutGradiantField = Delegate.CreateDelegate(
86+
typeof(Func<GUIContent, Gradient, GUILayoutOption[], Gradient>),
87+
typeof(EditorGUILayout).GetMethod(
88+
"GradientField",
89+
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static,
90+
null, CallingConventions.Any,
91+
new[] { typeof(GUIContent), typeof(Gradient), typeof(GUILayoutOption[]) },
92+
null
93+
)
94+
) as Func<GUIContent, Gradient, GUILayoutOption[], Gradient>;
7195

7296
internal static void InitPropertyTypeMapper() {
7397
if (propertyTypeMapper.Count > 0)
@@ -91,6 +115,7 @@ internal static void InitPropertyTypeMapper() {
91115
AddPropertyTypeMap("UnityEngine.Color, UnityEngine.dll", PropertyType.Color);
92116
AddPropertyTypeMap("UnityEngine.Rect, UnityEngine.dll", PropertyType.Rect);
93117
AddPropertyTypeMap("UnityEngine.Bounds, UnityEngine.dll", PropertyType.Bounds);
118+
AddPropertyTypeMap("UnityEngine.Gradient, UnityEngine.dll", PropertyType.Gradient);
94119
AddPropertyTypeMap("UnityEngine.AnimationCurve, UnityEngine.dll", PropertyType.Curve);
95120
AddPropertyTypeMap("UnityEngine.Object, UnityEngine.dll", PropertyType.Object);
96121
AddPropertyTypeMap("System.Collections.Generic.IList`1", PropertyType.Array);
@@ -403,6 +428,14 @@ internal static UnityObject ObjectField(Rect position, GUIContent label, UnityOb
403428
return value;
404429
}
405430

431+
internal static Gradient GradientField(Rect position, GUIContent label, Gradient value) {
432+
return doGradientField.Invoke(label, position, value);
433+
}
434+
435+
internal static Gradient GradientField(GUIContent label, Gradient value, params GUILayoutOption[] options) {
436+
return doLayoutGradiantField.Invoke(label, value, options);
437+
}
438+
406439
static void ClickObject(UnityObject obj) {
407440
var newClickTime = EditorApplication.timeSinceStartup;
408441
if (newClickTime - clickTime < 0.3 && obj != null)

UInspectorPlus/MethodPropertyDrawer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,12 @@ void DrawDirectField(bool readOnly, Rect? rect) {
586586
else
587587
value = EditorGUILayout.BoundsField(nameContent, Helper.GetOrDefault<Bounds>(value));
588588
break;
589+
case PropertyType.Gradient:
590+
if (rect.HasValue)
591+
value = Helper.GradientField(rect.Value, nameContent, Helper.GetOrDefault<Gradient>(value));
592+
else
593+
value = Helper.GradientField(nameContent, Helper.GetOrDefault<Gradient>(value));
594+
break;
589595
case PropertyType.Curve:
590596
if (rect.HasValue)
591597
value = EditorGUI.CurveField(rect.Value, nameContent, value as AnimationCurve ?? new AnimationCurve());

UInspectorPlus/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
// 組件的一般資訊是由下列的屬性集控制。
66
// 變更這些屬性的值即可修改組件的相關
77
// 資訊。
8-
[assembly: AssemblyTitle("UInspectorPlus")]
8+
[assembly: AssemblyTitle("Inspector+")]
99
[assembly: AssemblyDescription("")]
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("")]
12-
[assembly: AssemblyProduct("UInspectorPlus")]
13-
[assembly: AssemblyCopyright("Copyright © 2018")]
12+
[assembly: AssemblyProduct("Inspector+")]
13+
[assembly: AssemblyCopyright("Copyright © Jeremy Lam \"JLChnToZ\" 2016-2018")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,5 +32,5 @@
3232
// 您可以指定所有的值,或將組建編號或修訂編號設為預設值
3333
//方法是使用 '*',如下所示:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
35+
[assembly: AssemblyVersion("0.1.0.0")]
36+
[assembly: AssemblyFileVersion("0.1.0.0")]

0 commit comments

Comments
 (0)