public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var typePopupProperty = GetTypePopupProperty(property); if (typePopupProperty == null) { EditorGUI.PropertyField(position, property, label, property.isExpanded); return; } List <Type> types; string[] displayedOptions; int[] optionValues; int selectedIndex = GetTypePopupFromProperty(typePopupProperty, attribute as TypePopupAttribute, out types, out displayedOptions, out optionValues); if (!useSearchDict.ContainsKey(typePopupProperty.propertyPath)) { useSearchDict.Add(typePopupProperty.propertyPath, false); } useSearchDict[typePopupProperty.propertyPath] = EditorGUI.Foldout(new Rect(position.position, new Vector2(EasyGUI.Indent, EditorGUIUtility.singleLineHeight + 3)), useSearchDict[typePopupProperty.propertyPath], GUIContent.none); EditorGUI.BeginChangeCheck(); var index = EditorGUI.IntPopup(new Rect(position.position, new Vector2(position.width, EditorGUIUtility.singleLineHeight + 3)), typePopupProperty.displayName, selectedIndex, displayedOptions, optionValues); if (EditorGUI.EndChangeCheck()) { typePopupProperty.stringValue = index == 0 ? null : types[index].FullName; } if (useSearchDict[typePopupProperty.propertyPath]) { var height = EditorGUIUtility.singleLineHeight + 5; var searchPosition = new Rect(new Vector2(position.x - EasyGUI.Indent, position.y + height), new Vector2(position.width, height)); searchCondition = EasyGUI.SearchFieldWithPopupMenu(searchPosition, SearchLabelStr, searchField, searchCondition, popupMenu => { foreach (var type in types.Where(type => type != null && type.FullName.ToLower().Contains(searchCondition.ToLower()))) { popupMenu.AddItem(new GUIContent(type.Name), false, () => { typePopupProperty.stringValue = type.FullName; typePopupProperty.serializedObject.ApplyModifiedProperties(); searchCondition = EmptyStr; }); } }, SearchLabelHtmlString, SearchLabelTooltipStr); } if (property.type == SerializableEventObjectTypeStr) { var targetProperty = property.FindPropertyRelative(TargetStr); var targetPosition = new Rect(new Vector2(position.x - EasyGUI.Indent, position.y + (useSearchDict[typePopupProperty.propertyPath] ? (2 * EditorGUIUtility.singleLineHeight + 5) : EditorGUIUtility.singleLineHeight) + 5), new Vector2(position.width, EditorGUIUtility.singleLineHeight)); EditorGUI.ObjectField(targetPosition, targetProperty); } }
public override void OnGUI(Rect position, InspectableProperty property, GUIContent label) { List <Type> types; string[] displayedOptions; int[] optionValues; int selectedIndex = GetTypePopupFromProperty(property, Attribute as TypePopupAttribute, out types, out displayedOptions, out optionValues); if (!useSearchIndex.ContainsKey(property.PropertyPath)) { useSearchIndex.Add(property.PropertyPath, false); } useSearchIndex[property.PropertyPath] = EditorGUI.Foldout(new Rect(position.position, new Vector2(EasyGUI.Indent, EditorGUIUtility.singleLineHeight + 3)), useSearchIndex[property.PropertyPath], GUIContent.none); EditorGUI.BeginChangeCheck(); var index = EditorGUI.IntPopup(new Rect(position.position, new Vector2(position.width, EditorGUIUtility.singleLineHeight + 3)), property.DisplayName, selectedIndex, displayedOptions, optionValues); if (EditorGUI.EndChangeCheck()) { property.StringValue = index == 0 ? null : types[index].FullName; } if (useSearchIndex[property.PropertyPath]) { var height = EditorGUIUtility.singleLineHeight + 3; var searchPosition = new Rect(new Vector2(position.x - EasyGUI.Indent, position.y + height), new Vector2(position.width, height)); searchCondition = EasyGUI.SearchFieldWithPopupMenu(searchPosition, SearchLabelStr, searchField, searchCondition, popupMenu => { foreach (var type in types.Where(type => type != null && type.FullName.ToLower().Contains(searchCondition.ToLower()))) { popupMenu.AddItem(new GUIContent(type.Name), false, () => { property.StringValue = type.FullName; property.InspectableObject.ApplyModifiedProperties(); searchCondition = EmptyStr; }); } }, SearchLabelHtmlString, SearchLabelTooltipStr); } }