zoukankan      html  css  js  c++  java
  • Unity 编辑器扩展自定义窗体

    这次看见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程序研究院 发表

    如果你感兴趣,你可以把你妹妹介绍给我
  • 相关阅读:
    常见浏览器兼容性问题与解决方案
    [WinForm] VS2010发布、打包安装程序
    前端和后台对时间数值的增减操作(JavaScript和C#两种方法)
    C#类的继承,方法的重载和覆写
    web.config设置和取值
    linux nginx安装
    java Arrays.asList()和Collections.addAll()
    mysql数据库乱码
    Mysql不区分大小写
    ueditor
  • 原文地址:https://www.cnblogs.com/plateFace/p/4287047.html
Copyright © 2011-2022 走看看