From cc94b8dfcf1d80520033624594ee4bacaf5cadb6 Mon Sep 17 00:00:00 2001 From: "kaichi.oda" Date: Fri, 3 Jul 2020 21:33:58 +0900 Subject: [PATCH 1/2] add draganddrop receive function --- .../Editor/PointCloudImporterWindow.cs | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Editor/PointCloudImporterWindow.cs b/Assets/Scripts/Editor/PointCloudImporterWindow.cs index d6150e585..f762f764c 100644 --- a/Assets/Scripts/Editor/PointCloudImporterWindow.cs +++ b/Assets/Scripts/Editor/PointCloudImporterWindow.cs @@ -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; @@ -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) @@ -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(); @@ -270,6 +270,41 @@ private void DrawSettingsSection() } } + private void ReceiveDragAndDropArea(Rect dropRect, System.Action 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 => AllowedExtensions.Contains(Path.GetExtension(x))).Select(p => Path.GetFullPath(p)).ToArray(); + { + System.Text.StringBuilder sb = new System.Text.StringBuilder(); + foreach (var p in fullpathArray) + { + sb.AppendLine(p); + } + Debug.Log(sb.ToString()); + } + if (0 < fullpathArray.Length) + { + DragAndDrop.visualMode = DragAndDropVisualMode.Copy; + } + if (dndCallback != null) + { + dndCallback(fullpathArray); + } + DragAndDrop.activeControlID = 0; + Event.current.Use(); + break; + } + + } + private void DrawInputFilesInspector() { const float addFileButtonWidth = 65; @@ -379,6 +414,10 @@ private void DrawInputFilesInspector() // var rect = CreateBox(4); + // TODO:dndをここに + ReceiveDragAndDropArea(rect, null); + + // Refresh element count, to include additions/removals elementCount = inputFiles.arraySize; if (elementCount == 0) From 527e7373e5e589d73114c6d0459b269837130a62 Mon Sep 17 00:00:00 2001 From: "kaichi.oda" Date: Mon, 6 Jul 2020 10:37:21 +0900 Subject: [PATCH 2/2] fix drop action and set pointcloud file path --- .../Editor/PointCloudImporterWindow.cs | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/Assets/Scripts/Editor/PointCloudImporterWindow.cs b/Assets/Scripts/Editor/PointCloudImporterWindow.cs index f762f764c..6fbe8be83 100644 --- a/Assets/Scripts/Editor/PointCloudImporterWindow.cs +++ b/Assets/Scripts/Editor/PointCloudImporterWindow.cs @@ -281,28 +281,26 @@ private void ReceiveDragAndDropArea(Rect dropRect, System.Action dndCa if (!dropRect.Contains(evt.mousePosition)) break; - var fullpathArray = DragAndDrop.paths.Where(x => AllowedExtensions.Contains(Path.GetExtension(x))).Select(p => Path.GetFullPath(p)).ToArray(); - { - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - foreach (var p in fullpathArray) - { - sb.AppendLine(p); - } - Debug.Log(sb.ToString()); - } + 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 (dndCallback != null) + + + if (evt.type == EventType.DragPerform) { - dndCallback(fullpathArray); + DragAndDrop.AcceptDrag(); + + if (dndCallback != null) + { + dndCallback(fullpathArray); + } + DragAndDrop.activeControlID = 0; } - DragAndDrop.activeControlID = 0; Event.current.Use(); break; } - } private void DrawInputFilesInspector() @@ -414,8 +412,24 @@ private void DrawInputFilesInspector() // var rect = CreateBox(4); - // TODO:dndをここに - ReceiveDragAndDropArea(rect, null); + 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