private void RenderDragAndDropReceivers() { Rect dropContainer = EditorGUILayout.BeginHorizontal(GUILayout.MinHeight(80f)); GUILayout.Space(80f); dropContainer.width = (dropContainer.width * 0.5f) - 5f; Color originalColor = GUI.backgroundColor; GUI.backgroundColor = inclusionColor; GUI.Box(dropContainer, "Drag Included Items Here", midCenterLabelledBoxStyle); inclusionDragReceiver.ReceiverBox = dropContainer.WithPosition( GUIUtility.GUIToScreenPoint(dropContainer.position)); inclusionDragReceiver.Update(); dropContainer.x += dropContainer.width + 15f; dropContainer.width -= 5f; GUI.backgroundColor = exclusionColor; GUI.Box(dropContainer, "Drag Excluded Items Here", midCenterLabelledBoxStyle); GUI.backgroundColor = originalColor; exclusionDragReceiver.ReceiverBox = dropContainer.WithPosition( GUIUtility.GUIToScreenPoint(dropContainer.position)); exclusionDragReceiver.Update(); EditorGUILayout.EndHorizontal(); }
/// <summary> /// Creates a text field that can have any item dragged onto it and the folder /// it is a part of populates the text field /// </summary> /// <param name="folderValue">The current value</param> /// <param name="label">Any label to display</param> /// <param name="rectOffset">Offset to apply to the rectangle. This is necessary because the position is returned /// relative to the EditorWindow. To get this value from an EditorWindow class, simply pass in position.position. /// If you don't need an offset, pass in Vector2.zero</param> /// <param name="options">Any layout options to forward along</param> /// <returns>The new input if changes were made, otherwise the existing</returns> public static string FolderTextbox(string folderValue, GUIContent label, Vector2 rectOffset, params GUILayoutOption[] options) { if (folderReceiver == null) { folderReceiver = new DragReceiver(DragReceiver.IsValidFunc, UnityEditor.DragAndDropVisualMode.Link); } folderValue = EditorGUILayout.DelayedTextField(label, folderValue, options); folderReceiver.ReceiverBox = GUILayoutUtility.GetLastRect(); folderReceiver.ReceiverBox = new Rect(folderReceiver.ReceiverBox.x + rectOffset.x, folderReceiver.ReceiverBox.y + rectOffset.y, folderReceiver.ReceiverBox.width, folderReceiver.ReceiverBox.height); System.EventHandler action = (sender, e) => { folderValue = DragAndDrop.paths[0]; if (!System.IO.Directory.Exists(folderValue)) { folderValue = System.IO.Path.GetDirectoryName(DragAndDrop.paths[0]); } if (!folderValue.EndsWith("/")) { folderValue += "/"; } }; folderReceiver.OnDragComplete += action; folderReceiver.Update(); folderReceiver.OnDragComplete -= action; return(folderValue); }
private void OnGUI() { if (descriptionStyle == null) { InitializeStyles(); } folderDrag.ReceiverBox = position; Debug.Log(position); Debug.Log(GUIUtility.GUIToScreenPoint(Event.current.mousePosition)); EditorGUILayout.LabelField(DescriptionText, descriptionStyle); EditorGUILayout.Space(); selectedFolder = EditorGUILayout.TextField("Folder Path:", selectedFolder, folderTextboxStyle); folderDrag.Update(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("OK", dialogButtonStyle)) { Ok(); } if (GUILayout.Button("Cancel", dialogButtonStyle)) { Cancel(close: true); } EditorGUILayout.EndHorizontal(); }