-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathMainWindow.cs
More file actions
80 lines (71 loc) · 2.38 KB
/
MainWindow.cs
File metadata and controls
80 lines (71 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace ToolKits
{
/// <summary>
/// 编辑器主界面
/// </summary>
public class MainWindow : EditorWindowBase
{
private static MainWindow window;
private static Vector2 minResolution = new Vector2(800, 600);
private static Rect middleCenterRect = new Rect(200, 100, 400, 400);
private GUIStyle labelStyle;
/// <summary>
/// 对外的访问接口
/// </summary>
[MenuItem("Tools/MultiWindowLayerManagement", priority = 17)]
public static void Popup()
{
window = EditorWindow.GetWindow(typeof(MainWindow), true, "多重窗口编辑器") as MainWindow;
window.minSize = minResolution;
window.Init();
EditorWindowMgr.AddEditorWindow(window);
window.Show();
}
/// <summary>
/// 在这里可以做一些初始化工作
/// </summary>
private void Init()
{
Priority = 1;
labelStyle = new GUIStyle();
labelStyle.normal.textColor = Color.red;
labelStyle.alignment = TextAnchor.MiddleCenter;
labelStyle.fontSize = 14;
labelStyle.border = new RectOffset(1, 1, 2, 2);
}
private void OnGUI()
{
ShowEditorGUI();
}
/// <summary>
/// 绘制编辑器界面
/// </summary>
private void ShowEditorGUI()
{
GUILayout.BeginArea(middleCenterRect);
GUILayout.BeginVertical();
EditorGUILayout.LabelField("点击下面的按钮创建重复弹出窗口", labelStyle, GUILayout.Width(220));
if (GUILayout.Button("创建窗口", GUILayout.Width(80)))
{
RepeateWindow.Popup(window.position.position);
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
private void OnDestroy()
{
//主界面销毁的时候,附带销毁创建出来的子界面
EditorWindowMgr.RemoveEditorWindow(window);
EditorWindowMgr.DestoryAllWindow();
}
private void OnFocus()
{
//重写OnFocus方法,让EditorWindowMgr去自动排序汇聚焦点
EditorWindowMgr.FoucusWindow();
}
}
}