11using UnityEngine ;
22using UnityEditor ;
3+ using UnityEditorInternal ;
34using System ;
5+ using System . Collections ;
46using System . Collections . Generic ;
57using System . Reflection ;
68using System . Linq ;
@@ -15,7 +17,10 @@ class InspectorDrawer {
1517 public bool changed ;
1618 public string searchText ;
1719 public event Action OnRequireRedraw ;
18- Type targetType ;
20+ Type targetType , elementType ;
21+ HexEdit hexEdit ;
22+ List < MethodPropertyDrawer > arrayContentDrawer ;
23+ ReorderableList arrayHandler ;
1924
2025 public InspectorDrawer ( object target , bool shown , bool showProps , bool showPrivateFields , bool showObsolete , bool showMethods ) {
2126 this . target = target ;
@@ -24,6 +29,7 @@ public InspectorDrawer(object target, bool shown, bool showProps, bool showPriva
2429 if ( showPrivateFields )
2530 flag |= BindingFlags . NonPublic ;
2631 targetType = target . GetType ( ) ;
32+ elementType = Helper . GetGenericListType ( targetType ) ;
2733 var fields = targetType . GetFields ( flag ) ;
2834 var props = ! showProps ? null : targetType . GetProperties ( flag ) . Where ( prop => prop . GetIndexParameters ( ) . Length == 0 ) . ToArray ( ) ;
2935 isInternalType = ! ( target is MonoBehaviour ) || Attribute . IsDefined ( target . GetType ( ) , typeof ( ExecuteInEditMode ) ) ;
@@ -68,7 +74,7 @@ public InspectorDrawer(object target, bool shown, bool showProps, bool showPriva
6874 }
6975
7076 public void Draw ( bool drawHeader = true , bool readOnly = false ) {
71- if ( target == null ) {
77+ if ( target == null ) {
7278 EditorGUILayout . InspectorTitlebar ( false , null as UnityObject ) ;
7379 return ;
7480 }
@@ -80,6 +86,44 @@ public void Draw(bool drawHeader = true, bool readOnly = false) {
8086 }
8187 EditorGUI . indentLevel ++ ;
8288 EditorGUILayout . BeginVertical ( ) ;
89+ if ( elementType != null ) {
90+ if ( targetType == typeof ( byte [ ] ) ) {
91+ if ( hexEdit == null )
92+ hexEdit = new HexEdit ( ) ;
93+ hexEdit . data = target as byte [ ] ;
94+ if ( hexEdit . data != null )
95+ hexEdit . DrawGUI ( false , GUILayout . MinHeight ( EditorGUIUtility . singleLineHeight ) , GUILayout . ExpandHeight ( true ) ) ;
96+ } else {
97+ if ( arrayHandler == null ) {
98+ if ( arrayContentDrawer == null ) {
99+ arrayContentDrawer = new List < MethodPropertyDrawer > ( ) ;
100+ for ( int i = 0 ; i < ( target as IList ) . Count ; i ++ )
101+ ListAddItem ( ) ;
102+ }
103+ arrayHandler = new ReorderableList ( target as IList , elementType ) ;
104+ arrayHandler . headerHeight = EditorGUIUtility . singleLineHeight ;
105+ arrayHandler . elementHeight = EditorGUIUtility . singleLineHeight + 2 ;
106+ arrayHandler . drawElementCallback = ( r , i , c , d ) => {
107+ arrayContentDrawer [ i ] . Value = ( target as IList ) [ i ] ;
108+ arrayContentDrawer [ i ] . Draw ( false , Helper . ScaleRect ( r , offsetHeight : - 2 ) ) ;
109+ if ( arrayContentDrawer [ i ] . Changed )
110+ ( target as IList ) [ i ] = arrayContentDrawer [ i ] . Value ;
111+ } ;
112+ arrayHandler . drawHeaderCallback = r => GUI . Label ( r , target . ToString ( ) , EditorStyles . boldLabel ) ;
113+ arrayHandler . onCanAddCallback = l => target != null && ! ( target as IList ) . IsFixedSize ;
114+ arrayHandler . onCanRemoveCallback = arrayHandler . onCanAddCallback . Invoke ;
115+ arrayHandler . onAddCallback = l => {
116+ ReorderableList . defaultBehaviours . DoAddButton ( l ) ;
117+ ListAddItem ( ) ;
118+ } ;
119+ arrayHandler . onRemoveCallback = l => {
120+ ReorderableList . defaultBehaviours . DoRemoveButton ( l ) ;
121+ arrayContentDrawer . RemoveAt ( 0 ) ;
122+ } ;
123+ }
124+ arrayHandler . DoLayoutList ( ) ;
125+ }
126+ }
83127 foreach ( var item in drawer ) {
84128 var methodDrawer = item as ComponentMethodDrawer ;
85129 var fieldDrawer = item as MethodPropertyDrawer ;
@@ -124,6 +168,12 @@ public void Draw(bool drawHeader = true, bool readOnly = false) {
124168 EditorGUI . indentLevel -- ;
125169 }
126170
171+ void ListAddItem ( object value = null ) {
172+ var drawer = new MethodPropertyDrawer ( elementType , "" , value , true , false ) ;
173+ drawer . OnRequireRedraw += RequireRedraw ;
174+ arrayContentDrawer . Add ( drawer ) ;
175+ }
176+
127177 public void UpdateValues ( bool updateProps ) {
128178 if ( target == null ) return ;
129179 foreach ( var drawerItem in drawer ) {
0 commit comments