55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public class CustomEditorPanel : EditorWindow
|
|
{
|
|
private GameObject draggedObject;
|
|
|
|
[MenuItem("Window/Custom Editor Panel")]
|
|
public static void ShowWindow()
|
|
{
|
|
GetWindow<CustomEditorPanel>("Custom Editor Panel");
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
Event currentEvent = Event.current;
|
|
Rect dropArea = GUILayoutUtility.GetRect(0, 50, GUILayout.ExpandWidth(true));
|
|
|
|
GUI.Box(dropArea, "拖过去会在节点下新建一个空节点");
|
|
|
|
switch (currentEvent.type)
|
|
{
|
|
case EventType.DragUpdated:
|
|
case EventType.DragPerform:
|
|
if (!dropArea.Contains(currentEvent.mousePosition))
|
|
break;
|
|
|
|
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
|
|
|
if (currentEvent.type == EventType.DragPerform)
|
|
{
|
|
DragAndDrop.AcceptDrag();
|
|
|
|
foreach (GameObject dragged in DragAndDrop.objectReferences)
|
|
{
|
|
draggedObject = dragged;
|
|
|
|
// 创建新的GameObject作为子节点
|
|
GameObject newObject = new GameObject("New Object");
|
|
newObject.name = dragged.name;
|
|
newObject.transform.SetParent(draggedObject.transform);
|
|
newObject.transform.localPosition = Vector3.zero;
|
|
}
|
|
}
|
|
|
|
Event.current.Use();
|
|
break;
|
|
}
|
|
|
|
if (draggedObject != null)
|
|
{
|
|
EditorGUILayout.LabelField("Dragged GameObject:", draggedObject.name);
|
|
}
|
|
}
|
|
} |