Skip to content
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

Feature/pointcloudimporter support file dnd #838

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 58 additions & 5 deletions Assets/Scripts/Editor/PointCloudImporterWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ static Styles()

ListStyleA = new GUIStyle
{
normal = {background = bgTexA, textColor = textColor},
normal = { background = bgTexA, textColor = textColor },
padding = padding,
clipping = TextClipping.Clip
};
ListStyleB = new GUIStyle
{
normal = {background = bgTexB, textColor = textColor},
normal = { background = bgTexB, textColor = textColor },
padding = padding,
clipping = TextClipping.Clip
};
}

public static readonly GUIStyle TitleLabelStyle = new GUIStyle(GUI.skin.label)
{alignment = TextAnchor.MiddleCenter, fontSize = 14};
{ alignment = TextAnchor.MiddleCenter, fontSize = 14 };

public static readonly GUIStyle ListStyleA;
public static readonly GUIStyle ListStyleB;
Expand Down Expand Up @@ -240,7 +240,7 @@ private void DrawSettingsSection()
EditorGUILayout.PropertyField(maxTreeDepth);
EditorGUILayout.PropertyField(minPointDistance);
}

EditorGUILayout.Space();
generateMesh.isExpanded = EditorGUILayout.Foldout(generateMesh.isExpanded, "Mesh Settings", EditorStyles.foldoutHeader);
if (generateMesh.isExpanded)
Expand All @@ -251,7 +251,7 @@ private void DrawSettingsSection()
EditorGUILayout.PropertyField(roadOnlyMesh);
if (roadOnlyMesh.boolValue)
EditorGUILayout.HelpBox("Road detection is not suitable for all data sets. If you experience problems, try again with this option off.", MessageType.Info);

EditorGUILayout.PropertyField(meshDetailLevel);
}
EditorGUI.EndDisabledGroup();
Expand All @@ -270,6 +270,39 @@ private void DrawSettingsSection()
}
}

private void ReceiveDragAndDropArea(Rect dropRect, System.Action<string[]> dndCallback = null)
{
var evt = Event.current;
int id = GUIUtility.GetControlID(FocusType.Passive);
switch (evt.type)
{
case EventType.DragUpdated:
case EventType.DragPerform:
if (!dropRect.Contains(evt.mousePosition))
break;

var fullpathArray = DragAndDrop.paths.Where(x => allowedExtensionsList.Contains(Path.GetExtension(x))).Select(p => Path.GetFullPath(p)).ToArray();
if (0 < fullpathArray.Length)
{
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
}


if (evt.type == EventType.DragPerform)
{
DragAndDrop.AcceptDrag();

if (dndCallback != null)
{
dndCallback(fullpathArray);
}
DragAndDrop.activeControlID = 0;
}
Event.current.Use();
break;
}
}

private void DrawInputFilesInspector()
{
const float addFileButtonWidth = 65;
Expand Down Expand Up @@ -379,6 +412,26 @@ private void DrawInputFilesInspector()
//
var rect = CreateBox(4);

ReceiveDragAndDropArea(rect, (list) =>
{
if (list == null || list.Length < 1)
{
return;
}
foreach (var nf in list)
{
var newFile = Utility.GetRelativePathIfApplies(nf);
CacheArrayProperty(inputFiles, tmpList);
if (!tmpList.Contains(newFile))
{
var index = inputFiles.arraySize;
inputFiles.InsertArrayElementAtIndex(index);
inputFiles.GetArrayElementAtIndex(index).stringValue = newFile;
}
}
});


// Refresh element count, to include additions/removals
elementCount = inputFiles.arraySize;
if (elementCount == 0)
Expand Down