public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { objectId = property.serializedObject.targetObject.GetInstanceID().ToString(); VectorFilterOptions options = (VectorFilterOptions)EditorHelper.GetTargetObjectOfProperty(property); showFilters = EditorGUILayout.Foldout(showFilters, new GUIContent { text = "Filters", tooltip = "Filter features in a vector layer based on criterion specified. " }); if (showFilters) { var propertyFilters = property.FindPropertyRelative("filters"); for (int i = 0; i < propertyFilters.arraySize; i++) { DrawLayerFilter(property, propertyFilters, i, options); } if (propertyFilters.arraySize > 0) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(property.FindPropertyRelative("combinerType")); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } } EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); GUILayout.Space(EditorGUI.indentLevel * 12); EditorGUI.BeginChangeCheck(); if (GUILayout.Button(new GUIContent("Add New Empty"), (GUIStyle)"minibutton")) { options.AddFilter(); } if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; } }
private void DrawLayerFilter(SerializedProperty originalProperty, SerializedProperty propertyFilters, int index, VectorFilterOptions vectorFilterOptions) { var property = propertyFilters.GetArrayElementAtIndex(index); var filterOperatorProp = property.FindPropertyRelative("filterOperator"); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent { text = "Key", tooltip = "Name of the property to use as key. This property is case sensitive." }, GUILayout.MaxWidth(150)); switch ((LayerFilterOperationType)filterOperatorProp.enumValueIndex) { case LayerFilterOperationType.IsEqual: case LayerFilterOperationType.IsGreater: case LayerFilterOperationType.IsLess: EditorGUILayout.LabelField(operatorGui, GUILayout.MaxWidth(150)); EditorGUILayout.LabelField(numValueGui, GUILayout.MaxWidth(100)); break; case LayerFilterOperationType.Contains: EditorGUILayout.LabelField(operatorGui, GUILayout.MaxWidth(150)); EditorGUILayout.LabelField(strValueGui, GUILayout.MaxWidth(100)); break; case LayerFilterOperationType.IsInRange: EditorGUILayout.LabelField(operatorGui, GUILayout.MaxWidth(150)); EditorGUILayout.LabelField(minValueGui, GUILayout.MaxWidth(100)); EditorGUILayout.LabelField(maxValueGui, GUILayout.MaxWidth(100)); break; default: break; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); var selectedLayerName = originalProperty.FindPropertyRelative("_selectedLayerName").stringValue; DrawPropertyDropDown(originalProperty, property); EditorGUI.BeginChangeCheck(); filterOperatorProp.enumValueIndex = EditorGUILayout.Popup(filterOperatorProp.enumValueIndex, filterOperatorProp.enumDisplayNames, GUILayout.MaxWidth(150)); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } EditorGUI.BeginChangeCheck(); switch ((LayerFilterOperationType)filterOperatorProp.enumValueIndex) { case LayerFilterOperationType.IsEqual: case LayerFilterOperationType.IsGreater: case LayerFilterOperationType.IsLess: property.FindPropertyRelative("Min").doubleValue = EditorGUILayout.DoubleField(property.FindPropertyRelative("Min").doubleValue, GUILayout.MaxWidth(100)); break; case LayerFilterOperationType.Contains: property.FindPropertyRelative("PropertyValue").stringValue = EditorGUILayout.TextField(property.FindPropertyRelative("PropertyValue").stringValue, GUILayout.MaxWidth(150)); break; case LayerFilterOperationType.IsInRange: property.FindPropertyRelative("Min").doubleValue = EditorGUILayout.DoubleField(property.FindPropertyRelative("Min").doubleValue, GUILayout.MaxWidth(100)); property.FindPropertyRelative("Max").doubleValue = EditorGUILayout.DoubleField(property.FindPropertyRelative("Max").doubleValue, GUILayout.MaxWidth(100)); break; default: break; } if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } if (GUILayout.Button(new GUIContent(" X "), (GUIStyle)"minibuttonright", GUILayout.Width(30))) { vectorFilterOptions.RemoveFilter(index); propertyFilters.DeleteArrayElementAtIndex(index); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }