-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for dragging and dropping multiple scene files on lists (& other collections) #85
Comments
This can be a bit tricky, but I'll see what we can do. |
Fortunately, Unity does provide some tools for working with drag and drop on the editor - here's a link to the DragAndDrop class docs. From what I've read, you can't implement PropertyDrawer scripts directy to generic classes such as Most implementations I've seen iterate over the The drag and drop logic (probably) will look something like this: public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (position.Contains(Event.current.mousePosition))
{
if (Event.current.type == EventType.DragUpdated
|| Event.current.type == EventType.DragPerform)
{
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
if (Event.current.type == EventType.DragPerform)
{
DragAndDrop.AcceptDrag();
foreach (Object draggedObj in DragAndDrop.objectReferences)
{
Debug.Log(draggedObj as SceneAsset);
// From here do whatever you want with the draggedObj.
}
}
Event.current.Use();
}
}
} |
I could not devise a pretty way to do this consistently. I am leaving the issue open until I devise a good approach, or someone smarter than me decides to take a stab at it. I am happy to accept PRs. |
I'll take a swing at it pretty soon enough. I got my editor script working on instancing my wrapper classes, so I'll see if I can work around making a property drawer for |
Let me run you through what I have thought of so far. I rejected all the options in my head for the reasons given:
As far as I know, it is not possible to overwrite |
Gonna give a go at 4; I was flirting around with the constants in |
I took a stab at this and reached the same conclusion as @starikcetin; i.e that there seems to be no elegant way of doing this without a (a) wrapper on List, or (b) dangerous touching of shared classes like Object or ReorderableLists or (c) forcing property drawers to do something it was not meant to do, potentially breaking things in unexpected ways or inconsistent behaviour between unity versions. IMHO, best solution might be to paste a link to an example in the documentation to a blob with code to a custom inspector that implements this functionality via an approach similar to: https://gist.github.com/bzgeb/3800350. That way users that need it can create their own inspector. |
Note for self: Investigate |
The issue:
The package doesn't allow populating a List of SceneReferences with multiple scene files in the inspector (via box selecting multiple files and dragging and dropping in the component's inspector).
Expected behavior:
Dragging and dropping multiple scene files into an list of SceneReferences should allow populating that list with the dropped files.
Steps to reproduce:
List<SceneReference>
;Other
sceneRef_issue.mp4
The text was updated successfully, but these errors were encountered: