Skip to content

Instantly share code, notes, and snippets.

@anchan828
Created October 2, 2013 09:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anchan828/c0f6c605f448cb67d3b3 to your computer and use it in GitHub Desktop.
Save anchan828/c0f6c605f448cb67d3b3 to your computer and use it in GitHub Desktop.
using System;
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
public class Question3_practical : EditorWindow
{
[MenuItem("Window/Question3_practical")]
static void Open()
{
GetWindow<Question3_practical>();
}
private List<Rect> rects = new List<Rect>();
void OnGUI()
{
if (Event.current.type == EventType.ContextClick)
{
GenericMenu menu = new GenericMenu();
menu.AddItem(new GUIContent("new Window"), false, () =>
{
rects.Add(new Rect(0, 0, 100, 100));
Repaint();
});
menu.ShowAsContext();
}
BeginWindows();
for (int index = 0; index < rects.Count; index++)
{
rects[index] = GUI.Window(index, rects[index], (id) =>
{
if (Event.current.type == EventType.ContextClick)
{
GenericMenu menu = new GenericMenu();
menu.AddItem(new GUIContent("Delete Window"), false, (data) =>
{
rects.Remove((Rect) data);
Repaint();
}, rects[id]);
menu.ShowAsContext();
}
GUI.DragWindow(new Rect(0, 0, 100, 16));
}, index.ToString());
}
EndWindows();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment