3
3
using UnityEditorInternal ;
4
4
using UnityEngine ;
5
5
6
- [ CustomEditor ( typeof ( RuntimeSet < > ) , true ) ]
6
+ [ CustomEditor ( typeof ( BaseRuntimeSet ) , true ) ]
7
7
public class RuntimeSetEditor : Editor
8
8
{
9
- private SOArchitectureBaseObject Target { get { return ( SOArchitectureBaseObject ) target ; } }
9
+ private BaseRuntimeSet Target { get { return ( BaseRuntimeSet ) target ; } }
10
10
private SerializedProperty DeveloperDescription { get { return serializedObject . FindProperty ( "DeveloperDescription" ) ; } }
11
-
11
+
12
+ private ReorderableList _reorderableList ;
13
+
14
+ private void OnEnable ( )
15
+ {
16
+ SerializedProperty items = serializedObject . FindProperty ( "_items" ) ;
17
+
18
+ string title = "List (" + Target . Type + ")" ;
19
+
20
+ _reorderableList = new ReorderableList ( serializedObject , items , false , true , false , true ) ;
21
+ _reorderableList . drawHeaderCallback += ( Rect rect ) => { EditorGUI . LabelField ( rect , title ) ; } ;
22
+ _reorderableList . drawElementCallback += DrawElement ;
23
+ _reorderableList . onRemoveCallback += Remove ;
24
+ _reorderableList . onChangedCallback += ( ReorderableList list ) => { Repaint ( ) ; } ;
25
+ }
12
26
public override void OnInspectorGUI ( )
13
27
{
14
- //EditorGUILayout.HelpBox("Cannot inspect sets. They're meant to contain runtime-data only, and assets cannot have those assigned through the editor", MessageType.Info);
28
+ serializedObject . Update ( ) ;
29
+
30
+ _reorderableList . DoLayoutList ( ) ;
15
31
16
32
EditorGUILayout . PropertyField ( DeveloperDescription ) ;
33
+
34
+ serializedObject . ApplyModifiedProperties ( ) ;
35
+ }
36
+ private void DrawElement ( Rect rect , int index , bool isActive , bool isFocused )
37
+ {
38
+ rect . height = EditorGUIUtility . singleLineHeight ;
39
+ rect . y ++ ;
40
+
41
+ SerializedProperty property = _reorderableList . serializedProperty . GetArrayElementAtIndex ( index ) ;
42
+
43
+ EditorGUI . BeginDisabledGroup ( true ) ;
44
+ EditorGUI . ObjectField ( rect , "Element " + index , property . objectReferenceValue , Target . Type , false ) ;
45
+ EditorGUI . EndDisabledGroup ( ) ;
46
+ }
47
+ private void Remove ( ReorderableList list )
48
+ {
49
+ Target . Items . RemoveAt ( list . index ) ;
17
50
}
18
51
}
0 commit comments