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