- Home /
Creating a "drop zone" for textures
Hi,
I would like to create a drag and drop zone to get some textures, something like this Picture:

On EditorWindow class, I have put a rect and I've attempted to create a drop zone, but without success.
 var dropZone = new Rect(10, 10, position.width - 10, 300);
             var primaryColor = GUI.color;
 
             if (Event.current.type == EventType.Repaint)
             {
                 var style = new GUIStyle();
                 GUI.color = Color.white;
                 style.Draw(dropZone, new GUIContent("DropZone"),0);
                 GUI.color = primaryColor;
             }
The text "DropZone" shows up, however the colored zone doesn't work. Any advice will be very helpful. Thanks!
Answer by Dunkelheit · Sep 03, 2014 at 03:01 PM
I FOUND a similar solution right on this thread. However I would like to know more ways to accomplish it. I have changed my code and so far it works well. I would like a more "stylized" drop zone even this one can fit it as well.
Now:

My current code to handle that:
 public static object[] DropZone(string title, int w, int h)
 {
     GUILayout.Box(title, GUILayout.Width(w), GUILayout.Height(h));
     var eventType = Event.current.type;
     bool isAccepted = false;
     if (eventType == EventType.DragUpdated || eventType == EventType.DragPerform)
     {
         DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
         if (eventType == EventType.dragPerform)
         {
             DragAndDrop.AcceptDrag();
             isAccepted = true;
         }
         
         Event.current.Use();
     }
     return isAccepted ? DragAndDrop.objectReferences : null;
 }
OnGUI() method we call this new method and check if dropped file is actually a texture.
     var objs = DropZone("Drop Textures Here", 300, 200);
     if (objs != null)
     {
         foreach (var o in objs)
         {
             if (o is Texture2D)
                 Debug.Log("Obj: " + o);
         }
     }
Please, if you have some interesting information, share with us on this thread. I'll appreciate that.
Next step is somehow render all added textures with its name and its position. I need to handle an array with sub-window, how can I accomplish that??
Your answer
 
 
             Follow this Question
Related Questions
Drag GameObject onto EditorWindow 0 Answers
DragAndDrop Problems, Returns wrong GameObject! 1 Answer
Editor GUI Drag Selection Box 1 Answer
NavMeshAgent stop 1 Answer
setactive true in OnBeginDrag 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                