上次的拖動窗口已經(jīng)畫出來了庶骄,這次我們看看怎么將兩個窗口用連線連接起來吧澳眷。我們在上一篇的程序中习柠,再增加一些代碼蒜焊,如下
using UnityEngine;
using UnityEditor;
public class NodeEditor : EditorWindow {
//窗口的矩形
Rect windowRect = new Rect(50, 50, 150, 100);
Rect windowRect2 = new Rect(100, 100, 150, 100);
//窗口的ID
int windownID = 0;
int windownID2 = 0;
static void ShowEditor() {
NodeEditor editor = EditorWindow.GetWindow<NodeEditor>();
}
void OnGUI() {
//繪畫窗口
BeginWindows();
windowRect = GUI.Window(windownID, windowRect, DrawNodeWindow, "Demo Window");
windowRect2 = GUI.Window(windownID2,windowRect2,DrawNodeWindow,"Demo Window2");
EndWindows();
//連接窗口
DrawNodeCurve(windowRect,windowRect2);
}
//繪畫窗口函數(shù)
void DrawNodeWindow(int id) {
//創(chuàng)建一個GUI Button
if (GUILayout.Button("Link")) {
Debug.Log("Clikc Link Button");
}
//設(shè)置改窗口可以拖動
GUI.DragWindow();
}
void DrawNodeCurve(Rect start, Rect end , Color color) {
Vector3 startPos = new Vector3(start.x + start.width, start.y + start.height / 2, 0);
Vector3 endPos = new Vector3(end.x, end.y + end.height / 2, 0);
Vector3 startTan = startPos + Vector3.right * 50;
Vector3 endTan = endPos + Vector3.left * 50;
Handles.DrawBezier(startPos, endPos, startTan, endTan, color, null, 4);
}
}
運行Editor倒信,出現(xiàn)這樣的效果,是不是很帥氣山涡?當然堤结,這還只是一些初步的代碼,不過還是分享給大家學(xué)習鸭丛,祝大家早日做好節(jié)點編輯器