public static void Open(SerializedProperty property) { GeocodeAttributeSearchWindow window = EditorWindow.GetWindow <GeocodeAttributeSearchWindow>(true, "Search for location"); window._property = property; Event e = Event.current; Vector2 mousePos = GUIUtility.GUIToScreenPoint(e.mousePosition); window.position = new Rect(mousePos.x - width, mousePos.y, width, height); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { float buttonWidth = EditorGUIUtility.singleLineHeight * 4; Rect fieldRect = new Rect(position.x, position.y, position.width - buttonWidth, EditorGUIUtility.singleLineHeight); Rect buttonRect = new Rect(position.x + position.width - buttonWidth, position.y, buttonWidth, EditorGUIUtility.singleLineHeight); EditorGUI.PropertyField(fieldRect, property); if (GUI.Button(buttonRect, searchButtonContent)) { GeocodeAttributeSearchWindow.Open(property); } }
private void ShowAddressOrLatLonUI(SerializedProperty property) { //EditorGUILayout.BeginVertical(); var coordinateProperties = property.FindPropertyRelative("coordinates"); for (int i = 0; i < coordinateProperties.arraySize; i++) { EditorGUILayout.BeginHorizontal(); //get the element to draw var coordinate = coordinateProperties.GetArrayElementAtIndex(i); //label for each location. var coordinateLabel = String.Format("Location {0}", i); // draw coordinate string. EditorGUI.BeginChangeCheck(); coordinate.stringValue = EditorGUILayout.TextField(coordinateLabel, coordinate.stringValue); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property, true); } // draw search button. if (GUILayout.Button(new GUIContent(searchButtonContent), (GUIStyle)"minibuttonleft", GUILayout.MaxWidth(100))) { object propertyObject = EditorHelper.GetTargetObjectOfProperty(property); GeocodeAttributeSearchWindow.Open(coordinate, propertyObject); } //include a remove button in the row if (GUILayout.Button(new GUIContent(" X "), (GUIStyle)"minibuttonright", GUILayout.MaxWidth(30))) { coordinateProperties.DeleteArrayElementAtIndex(i); EditorHelper.CheckForModifiedProperty(property); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); GUILayout.Space(EditorGUIUtility.labelWidth - 3); if (GUILayout.Button(new GUIContent("Add Location"), (GUIStyle)"minibutton")) { coordinateProperties.arraySize++; var newElement = coordinateProperties.GetArrayElementAtIndex(coordinateProperties.arraySize - 1); newElement.stringValue = ""; EditorHelper.CheckForModifiedProperty(property); } EditorGUILayout.EndHorizontal(); }
public static void Open(SerializedProperty property, object objectToUpdate = null) { GeocodeAttributeSearchWindow window = EditorWindow.GetWindow <GeocodeAttributeSearchWindow>(true, "Search for location"); window._coordinateProperty = property; if (objectToUpdate != null) { window._objectToUpdate = objectToUpdate; } Event e = Event.current; Vector2 mousePos = GUIUtility.GUIToScreenPoint(e.mousePosition); window.position = new Rect(mousePos.x - width, mousePos.y, width, height); }