I want to write a custom editor, where in the user can drag a Texture2D onto a region (ScrollView) and show a Window/ScriptableWizard to allow the user to define how to convert the Texture2D to the underlying structure. Is there a way to allow this behavior. Only thing I care about is having a region to accept only Texture2D, of a custom size. The rest of the behavior after that should be trivial.
I haven’t tried this with a Texture2D but, in general, if you declare a public field with a specific type, then if the editor displays it at it all it will restrict drag and drop to that type.
There is a special variant on this behavior where, if you declare a public field of a Component type, then it will accept a GameObject but ONLY one that has that type as a component, and assign that game object’s matching component to the field.
Rect scrollViewRect = GUILayoutUtility.GetLastRect ();
if(Event.current.type == EventType.DragExited || Event.current.type == EventType.DragUpdated)
{
if(scrollViewRect.Contains(Event.current.mousePosition))
{
Texture2D objects = new Texture2D[DragAndDrop.objectReferences.Length];
int i = 0;
foreach(UnityEngine.Object obj in DragAndDrop.objectReferences)
{
if(obj is Texture2D)
{
objects = obj as Texture2D;
-
++i;*
-
}*
-
}*
-
for(int j = 0; j < i; ++j)*
-
{*
-
Debug.Log (objects[j]);*
-
}*
-
}*
-
}*
This is the cleanest way I could find of doing it. Do to the way Unity’s selection works it is not really possible to do this in a custom Editor with mulit-select. However using an EditorWindow you should be able to.