博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Unity 编辑器扩展自定义窗体
阅读量:4696 次
发布时间:2019-06-09

本文共 2396 字,大约阅读时间需要 7 分钟。

这次看见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. 暂时没有找到自定义窗体和组件之间是如何传递值的!

 

本文固定链接:

转载请注明: 2013年04月15日 于 发表

转载于:https://www.cnblogs.com/plateFace/p/4287047.html

你可能感兴趣的文章
Git Stash用法
查看>>
sql server 2008学习8 sql server存储和索引结构
查看>>
Jquery radio选中
查看>>
postgressql数据库中limit offset使用
查看>>
测试思想-集成测试 关于接口测试 Part 2
查看>>
php生成器使用总结
查看>>
T-SQL中的indexof函数
查看>>
javascript基础之数组(Array)对象
查看>>
mysql DML DDL DCL
查看>>
RAMPS1.4 3d打印控制板接线与测试1
查看>>
python with语句中的变量有作用域吗?
查看>>
24@Servlet_day03
查看>>
初级ant的学习
查看>>
memcached 细究(三)
查看>>
RSA System.Security.Cryptography.CryptographicException
查看>>
webservice整合spring cxf
查看>>
[解题报告] 100 - The 3n + 1 problem
查看>>
Entity Framework 学习高级篇1—改善EF代码的方法(上)
查看>>
Mybatis逆向工程配置文件详细介绍(转)
查看>>
String类的深入学习与理解
查看>>