This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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