unity 在editorwindow窗口下生成了好多子节点,想在这些子节点通过连线现在出来,并且是常态现在
时间: 2024-03-29 16:34:42 浏览: 14
你可以使用Unity自带的EditorGUIUtility.DrawCurve方法来实现在EditorWindow窗口下生成子节点并通过连线显示的效果。下面是一个简单的示例代码:
```csharp
using UnityEditor;
using UnityEngine;
public class ExampleWindow : EditorWindow
{
private Vector2 _startPoint;
private Vector2 _endPoint;
[MenuItem("Window/Example")]
private static void ShowWindow()
{
ExampleWindow window = GetWindow<ExampleWindow>();
window.Show();
}
private void OnGUI()
{
if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
{
_startPoint = Event.current.mousePosition;
}
else if (Event.current.type == EventType.MouseDrag && Event.current.button == 0)
{
_endPoint = Event.current.mousePosition;
Repaint();
}
Handles.BeginGUI();
Handles.DrawBezier(_startPoint, _endPoint, _startPoint + Vector2.up * 50f, _endPoint - Vector2.up * 50f, Color.white, null, 2f);
Handles.EndGUI();
}
}
```
这个示例代码会在EditorWindow中响应鼠标左键拖动事件,并绘制一条贝塞尔曲线作为连线。你可以根据自己的需求修改这个代码来生成节点并连接它们。