protected override void SetupArrayEx(DTFieldNode node, ArrayExAttribute attribute) { base.SetupArrayEx(node, attribute); node.ArrayEx.elementHeight = (EditorGUIUtility.wideMode || node.ArrayEx.count == 0) ? 21 : 42; node.ArrayEx.drawElementCallback = userValueElementGUI; node.ArrayEx.onAddCallback = userValueAdd; node.ArrayEx.onRemoveCallback = userValueDelete; }
/// <summary> /// Called to initialize a ReorderableList. Override to add custom behaviour /// </summary> /// <param name="node">field node</param> /// <param name="attribute">ArrayEx attribute of the field</param> protected virtual void SetupArrayEx(DTFieldNode node, ArrayExAttribute attribute) { // Defaults if (attribute.ShowHeader) { node.ArrayEx.drawHeaderCallback = (Rect r) => { EditorGUI.LabelField(r, node.GUIContent); if (attribute.DropTarget) { var ev = Event.current; switch (ev.type) { case EventType.DragUpdated: if (r.Contains(ev.mousePosition)) { var fieldType = node.serializedProperty.GetFieldType(); bool allowed = DragAndDrop.objectReferences.Length > 0 && DTEditorUtility.DragDropTypeMatch(fieldType); DragAndDrop.visualMode = allowed ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; } break; case EventType.DragPerform: if (r.Contains(ev.mousePosition)) { var objs = DTEditorUtility.DragDropGetObjectsOfType(node.serializedProperty.GetFieldType()); foreach (var o in objs) { int idx = node.serializedProperty.arraySize; node.serializedProperty.InsertArrayElementAtIndex(idx); node.serializedProperty.GetArrayElementAtIndex(idx).objectReferenceValue = o; } node.serializedObject.ApplyModifiedProperties(); } break; } } }; } node.ArrayEx.drawElementCallback = (Rect r, int index, bool isActive, bool isFocused) => { var e = node.ArrayEx.serializedProperty.GetArrayElementAtIndex(index); if (e != null) { EditorGUI.PropertyField(r, e); } }; }
/// <summary> /// Called to initialize a ReorderableList. Override to add custom behaviour /// </summary> /// <param name="node">field node</param> /// <param name="attribute">ArrayEx attribute of the field</param> protected virtual void SetupArrayEx(DTFieldNode node, ArrayExAttribute attribute) { // Defaults if (attribute.ShowHeader) { node.ArrayEx.drawHeaderCallback = (Rect r) => { EditorGUI.LabelField(r, node.GUIContent); }; } node.ArrayEx.drawElementCallback = (Rect r, int index, bool isActive, bool isFocused) => { var e = node.ArrayEx.serializedProperty.GetArrayElementAtIndex(index); if (e != null) { EditorGUI.PropertyField(r, e); } }; }