Creating a "drop zone" for textures


I would like to create a drag and drop zone to get some textures, something like this Picture:

alt text

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!

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.


alt text

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)
            isAccepted = true;

    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??