这次看见Unity还可以自定义弹出窗体,让我很好奇.于是就去网上找文章看了看. 如果想自定义窗体需要把类放入Editor文件夹下面.

代码如下:

using UnityEngine;
using UnityEditor; public class MyEditor : EditorWindow
{
[MenuItem("GameObject/window")]
static void AddWindow()
{
Rect wr = new Rect(0, 0, 500, 500);
MyEditor window = (MyEditor)EditorWindow.GetWindowWithRect(typeof(MyEditor), wr, true, "盘子脸");
} 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("当窗口关闭时候调用");
}
}

1. 暂时没有找到自定义窗体和组件之间是如何传递值的!

本文固定链接: http://www.xuanyusong.com/archives/2211

转载请注明: 雨松MOMO 2013年04月15日 于 雨松MOMO程序研究院 发表

最新文章

  1. C++11之lambda表达式
  2. Struts 2 Spring Hibernate三大框架的执行流程以及原理
  3. 【转】mac/linux终端光标的快捷键操作
  4. <1> perl概述
  5. 微信公众平台开发-OAuth2.0网页授权(含源码)
  6. Graphic
  7. L2-006 树的遍历 (25 分) (根据后序遍历与中序遍历建二叉树)
  8. 【Alpha】Scrum Meeting 10
  9. Windows下安装Confluence并破解汉化
  10. opencv利用Cascade Classifier训练人脸检测器
  11. Spring Cloud 入门教程(五): Ribbon实现客户端的负载均衡
  12. myeclipse的web项目导入到eclipse中
  13. Shiro学习笔记(一)
  14. POJ1236或洛谷2746或洛谷2812 Network of Schools
  15. 分频器的verilog设计
  16. Iterative Quantization,ITQ
  17. Android中获取屏幕长宽的方法
  18. C#学习笔记(七):结构体、数组、冒泡排序和调试
  19. Python基础-画图:matplotlib
  20. SpringBoot无法启动,Process finished with exit code 0

热门文章

  1. JavaScript面向对象之类的创建
  2. DirectX 初始化DirectX(第一方式)
  3. 二叉排序树的创建删除中序输出&&平衡树
  4. Go语言程序的状态监控
  5. Android Service(下)
  6. Asp.net数据库缓存依赖
  7. confirm的用法 一般用于按钮操作时确定是否执行
  8. iOS-设计模式之代理反向传值
  9. hdu2037 经典贪心入门
  10. discuz x2 个人资料项排序问题解决方法、添加自定义字段、修改栏目名称和介绍