![](https://images2017.cnblogs.com/blog/548583/201708/548583-20170810131027589-728382634.png)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class MyEditor : EditorWindow {
[MenuItem("GameObject/window")]
static void AddWindow()
{
Rect wr=new Rect(0,0,500,500);
MyEditor windows=(MyEditor)EditorWindow.GetWindowWithRect(typeof(MyEditor),wr,true,"window name");
windows.Show();
}
private string text;
private Texture texture;
public void Awake()
{
texture = Resources.Load("1") as Texture;
}
void OnGUI()
{
//文本框
text = EditorGUILayout.TextField("输入文字",text);
if(GUILayout.Button("打开通知",GUILayout.Width(200)))
{
//打开一个通知栏
this.ShowNotification(new GUIContent("this is a notification"));
}
if(GUILayout.Button("关闭通知",GUILayout.Width(200)))
{
//关闭通知栏
this.RemoveNotification();
}
EditorGUILayout.LabelField("鼠标在窗口的位置",Event.current.mousePosition.ToString());
texture = EditorGUILayout.ObjectField("添加贴图",texture,typeof(Texture),true) as Texture;
if(GUILayout.Button("关闭窗口",GUILayout.Width(200)))
{
//关闭窗口
this.Close();
}
}
void OnFocus()
{
Debug.Log("当窗口获得焦点时调用一次");
}
void OnLostFocus()
{
Debug.Log("当窗口丢失焦点时调用一次");
}
void OnHierarchyChange()
{
Debug.Log("当Hierarchy视图中的任何对象发生改变时调用一次");
}
void OnProjectChange()
{
Debug.Log("当Project视图中的资源发生改变时调用一次");
}
void OnInspectorUpdate()
{
//重画
this.Repaint();
}
void OnSelectionChange()
{
foreach(Transform t in Selection.transforms)
{
Debug.Log("OnSelectionChange"+t.name);
}
}
void OnDestroy()
{
Debug.Log("当窗口关闭时调用");
}
}