Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class Question6_practical : EditorWindow
{
private Dictionary<int, Rect> windowRects = new Dictionary<int, Rect>();
[MenuItem("Window/Question6_practical")]
static void Open()
{
GetWindow<Question6_practical>();
}
void OnEnable()
{
AddRect(0, 1, 2, 3, 4, 5);
}
void OnGUI()
{
BeginWindows();
for (int i = 0; i < windowRects.Count; i++)
{
int windowID = windowRects.Keys.ElementAt(i);
windowRects[windowID] = GUI.Window(windowID, windowRects[windowID], (id) => GUI.DragWindow(), windowID.ToString());
if (i != 0)
{
int preWindowID = windowRects.Keys.ElementAt(i - 1);
DrawLine(windowRects[preWindowID], windowRects[windowID]);
}
}
EndWindows();
}
void AddRect(params int[] windowIDs)
{
foreach (int windowID in windowIDs)
{
windowRects.Add(windowID, new Rect(10 * windowID, 10 * windowID, 100, 100));
}
}
void DrawLine(Rect start, Rect end)
{
Vector2 startPos = new Vector2(start.x + start.width * 0.5f, start.y + start.height * 0.5f);
Vector2 endPos = new Vector2(end.x + end.width * 0.5f, end.y + end.height * 0.5f);
Handles.color = Color.black;
Handles.DrawLine(startPos, endPos);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment