Hello!
I’m working on an editor that list all assets from a certain type in my project.
It look like that:
I would like to be able to drag the asset in the left tree view to a corresponding variable exposed in the inspector, but I can’t find a way to do that… The thing is I don’t really know if I’m using the tree view correctly… when dragging in the tree view, should I be dragging rows? dragging a reference to the asset itself? What should I put in the DragAndDrop.SetGenericData?
It make a perfect transition to a second question, do you know a good ressource on tree view usage and best practice? I couldn’t find any ='(
Thank you for your help!!
Hi,
I hope it is not to late, but have you seen the TreeView Example Project ? For your specific case you can look for the TreeViewWithTreeModel class:
protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
{
if (hasSearch)
return;
DragAndDrop.PrepareStartDrag();
var draggedRows = GetRows().Where(item => args.draggedItemIDs.Contains(item.id)).ToList();
DragAndDrop.SetGenericData(k_GenericDragID, draggedRows);
DragAndDrop.objectReferences = new UnityEngine.Object[] { }; // this IS required for dragging to work
string title = draggedRows.Count == 1 ? draggedRows[0].displayName : "< Multiple >";
DragAndDrop.StartDrag (title);
}
geate. the answer above is what I need. well done
Nexer8
October 29, 2021, 1:38pm
4
DeepShade:
Hi,
I hope it is not to late, but have you seen the TreeView Example Project ? For your specific case you can look for the TreeViewWithTreeModel class:
protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
{
if (hasSearch)
return;
DragAndDrop.PrepareStartDrag();
var draggedRows = GetRows().Where(item => args.draggedItemIDs.Contains(item.id)).ToList();
DragAndDrop.SetGenericData(k_GenericDragID, draggedRows);
DragAndDrop.objectReferences = new UnityEngine.Object[] { }; // this IS required for dragging to work
string title = draggedRows.Count == 1 ? draggedRows[0].displayName : "< Multiple >";
DragAndDrop.StartDrag (title);
}
What did you use for k_GenericDragID? Anything special that needs to go there? Asking because the link no longer works.
k_GenericDragId is a string, and you can name it anything. For example, the tree control in the Timeline package has it set as:
const string k_GenericDragId = "TimelineDragging";