protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args)
{
DragAndDropVisualMode visualMode = DragAndDropVisualMode.None;
var draggedIDs = DragAndDrop.GetGenericData("BuildPlayerSceneTreeViewItem") as List <int>;
if (draggedIDs != null && draggedIDs.Count > 0)
{
visualMode = DragAndDropVisualMode.Move;
if (args.performDrop)
{
int newIndex = FindDropAtIndex(args);
var result = new List <TreeViewItem>();
int toInsert = 0;
foreach (var item in rootItem.children)
{
if (toInsert == newIndex)
{
foreach (var id in draggedIDs)
{
result.Add(FindItem(id, rootItem));
}
}
toInsert++;
if (!draggedIDs.Contains(item.id))
{
result.Add(item);
}
}
if (result.Count < rootItem.children.Count) //must be appending.
{
foreach (var id in draggedIDs)
{
result.Add(FindItem(id, rootItem));
}
}
rootItem.children = result;
EditorBuildSettings.scenes = GetSceneList();
ReloadAndSelect(draggedIDs);
Repaint();
}
}
else if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
{
visualMode = DragAndDropVisualMode.Copy;
if (args.performDrop)
{
var scenes = new List <EditorBuildSettingsScene>(EditorBuildSettings.scenes);
var scenesToAdd = new List <EditorBuildSettingsScene>();
var selection = new List <int>();
foreach (var path in DragAndDrop.paths)
{
if (AssetDatabase.GetMainAssetTypeAtPath(path) == typeof(SceneAsset))
{
var guid = new GUID(AssetDatabase.AssetPathToGUID(path));
selection.Add(guid.GetHashCode());
bool unique = true;
foreach (var scene in scenes)
{
if (scene.path == path)
{
unique = false;
break;
}
}
if (unique)
{
scenesToAdd.Add(new EditorBuildSettingsScene(path, true));
}
}
}
int newIndex = FindDropAtIndex(args);
scenes.InsertRange(newIndex, scenesToAdd);
EditorBuildSettings.scenes = scenes.ToArray();
ReloadAndSelect(selection);
Repaint();
}
}
return(visualMode);
}