Skip to content

Commit e3b3b7e

Browse files
committed
(WIP) Extend support for arrays to generic list interface.
- Update license.
1 parent adb603a commit e3b3b7e

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

Assets/Script Tester/Editor/Helpers.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ internal static void InitPropertyTypeMapper() {
8080
propertyTypeMapper.Add(typeof(Bounds), PropertyType.Bounds);
8181
propertyTypeMapper.Add(typeof(AnimationCurve), PropertyType.Curve);
8282
propertyTypeMapper.Add(typeof(UnityObject), PropertyType.Object);
83-
propertyTypeMapper.Add(typeof(Array), PropertyType.Array);
83+
propertyTypeMapper.Add(typeof(IList<>), PropertyType.Array);
8484
}
8585

8686
static readonly Hashtable storedState = new Hashtable();
@@ -437,6 +437,13 @@ internal static int ObjIdOrHashCode(object obj) {
437437
return obj.GetHashCode();
438438
return 0;
439439
}
440+
441+
internal static bool IsInterface(Type type, Type interfaceType) {
442+
foreach(var iType in type.GetInterfaces())
443+
if(iType == interfaceType || (iType.IsGenericType && iType.GetGenericTypeDefinition() == interfaceType))
444+
return true;
445+
return false;
446+
}
440447

441448
internal static GUIStyle GetGUIStyle(string styleName) {
442449
return GUI.skin.FindStyle(styleName) ?? EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle(styleName);

Assets/Script Tester/Editor/MethodPropertyDrawer.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using UnityEditor;
33
using UnityEditorInternal;
44
using System;
5+
using System.Collections;
56
using System.Collections.Generic;
67
using System.Linq;
78
using System.Reflection;
@@ -219,18 +220,19 @@ void ListAddItem(object value = null) {
219220

220221
void InitType() {
221222
Helper.InitPropertyTypeMapper();
222-
if(requiredType.IsArray) {
223+
if(Helper.IsInterface(requiredType, typeof(IList<>))) {
223224
castableTypes.Add(PropertyType.Array);
224225
currentType = PropertyType.Array;
225226
arrayHandler.headerHeight = EditorGUIUtility.singleLineHeight;
226-
arrayHandler.elementHeight = EditorGUIUtility.singleLineHeight;
227+
arrayHandler.elementHeight = EditorGUIUtility.singleLineHeight + 2;
227228
arrayHandler.drawHeaderCallback = r => EditorGUI.LabelField(r, name);
228-
arrayHandler.drawElementCallback = (r, i, c, d) => arrayContentDrawer[i].Draw(false, r);
229+
arrayHandler.drawElementCallback = (r, i, c, d) => arrayContentDrawer[i].Draw(false, Helper.ScaleRect(r, offsetHeight: -2));
229230
arrayHandler.onAddCallback = l => ListAddItem();
230231
arrayContentDrawer.Clear();
231-
if(rawValue != null)
232-
foreach(object item in (Array)rawValue)
233-
ListAddItem(item);
232+
var enumerable = rawValue as IEnumerable;
233+
if(enumerable != null)
234+
foreach(object item in enumerable)
235+
ListAddItem(item);
234236
return;
235237
}
236238
if(requiredType.IsByRef)

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Jeremy Lam (JLChnToZ)
3+
Copyright (c) 2014-2016 Jeremy Lam (JLChnToZ)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)