/// <summary> /// UI to add a new image marker to the marker library /// </summary> /// <param name="markerLibrary">The marker library currently being edited</param> static void DrawAddImageMarkerButton(MarsMarkerLibrary markerLibrary) { const int pickerID = 0xC0FFEE; const string objectSelectorClosed = "ObjectSelectorClosed"; if (GUILayout.Button(styles.AddImageMarkerButton, MarsEditorGUI.InternalEditorStyles.FooterButtonStyle, GUILayout.Width(Styles.AddRemoveButtonSize), GUILayout.Height(Styles.AddRemoveButtonSize))) { EditorGUIUtility.ShowObjectPicker <Texture2D>(null, false, "", pickerID); s_FlagSelectingMarker = true; } if (Event.current.commandName == objectSelectorClosed && EditorGUIUtility.GetObjectPickerControlID() == pickerID && s_FlagSelectingMarker) { var selectedTexture = EditorGUIUtility.GetObjectPickerObject() as Texture2D; const string addEmptyImage = "Add an empty image marker"; Undo.RecordObject(markerLibrary, addEmptyImage); markerLibrary.CreateAndAdd(); markerLibrary.SetGuid(markerLibrary.Count - 1, Guid.NewGuid()); markerLibrary.SetTexture(markerLibrary.Count - 1, selectedTexture); EditorUtility.SetDirty(markerLibrary); markerLibrary.SaveMarkerLibrary(); s_FlagSelectingMarker = false; } }
static void ProcessDragAndDropTexturesToMarkerConditionInspector(Event currentEvent, MarsMarkerLibrary currentMarkerLib) { if (currentEvent.type == EventType.DragUpdated) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; currentEvent.Use(); } else if (currentEvent.type == EventType.DragPerform) { Undo.RecordObject(currentMarkerLib, "Drag images to marker library"); for (var i = 0; i < DragAndDrop.objectReferences.Length; i++) { var draggedTexture = DragAndDrop.objectReferences[i] as Texture2D; if (draggedTexture != null) { currentMarkerLib.CreateAndAdd(); EditorUtility.SetDirty(currentMarkerLib); currentMarkerLib.SaveMarkerLibrary(); currentMarkerLib.SetGuid(currentMarkerLib.Count - 1, Guid.NewGuid()); currentMarkerLib.SetTexture(currentMarkerLib.Count - 1, draggedTexture); } } currentEvent.Use(); } }