一个简单的EditorWindow窗口:
在Editor文件夹下创建继承EditorWindow 的脚本,利用OnGUI方法回执界面(Update方法可用)
代码小示例:
using UnityEngine;
using UnityEditor;
using System.Collections;
public class MyEditorWindow : EditorWindow {
static MyEditorWindow window;
private bool isTrue = false;
private string time;
private string webTime;
private string inputStr="";
//在编辑器窗口菜单栏中添加MyWindow选项,点击运行Window调用Window方法,需using UnityEditor;
[MenuItem("MyWindow/Window")]
static void Window() {
if (window == null) {
window = (MyEditorWindow)GetWindow(typeof(MyEditorWindow));
}
//打开窗口
window.Show();
}
void OnGUI() {
GUI.BeginGroup(new Rect(10f, 10f, 280f, 250f), "", "box");
GUILayout.Label("时间:" + time);
isTrue = GUILayout.Toggle(isTrue, "按钮是否可用");
if (isTrue) {
if (GUI.Button(new Rect(10, 50, 80, 30), "更新时间")) {
time = System.DateTime.Now.ToString("HH:mm:ss");
}
}
GUI.Box(new Rect(10, 90, 250, 30), "");
GUI.Label(new Rect(10, 90, 250, 30), "输入的文字:" + inputStr);
inputStr = GUI.TextField(new Rect(10, 130, 150, 30), inputStr);
GUI.EndGroup();
}
}