Unity编辑器开关控制显示隐藏

一直想通过切换按钮实现编辑器上某些部分显示或者隐藏的功能。今天无意中实现了这个功能。原理很简单,编辑器面板上看到的都是绘制上去的,那么只要在特定时候不绘制就实现了这功能。

using UnityEditor;
using UnityEngine;

public class TestEditorWindow : EditorWindow
{
    [MenuItem ("EditorWindow/TestEditorWindow")]
    static void Init ()
    {
        EditorWindow.GetWindow<TestEditorWindow> ();
    }

    string mNotification = "通知消息";
    bool mNotificationShow = false;

    void OnGUI ()
    {
        #region 检测鼠标事件
//      wantsMouseMove = EditorGUILayout.Toggle ("Recive Movment : ", wantsMouseMove);
        wantsMouseMove = EditorGUILayout.BeginToggleGroup ("鼠标移动", wantsMouseMove);
        if (wantsMouseMove) {
            EditorGUILayout.Vector2Field ("    鼠标位置", Event.current.mousePosition);
            if (Event.current.type == EventType.MouseMove && wantsMouseMove) {
                Repaint ();
            }
        }
        EditorGUILayout.EndToggleGroup ();
        #endregion

        #region 显示通知消息
        mNotificationShow = EditorGUILayout.BeginToggleGroup ("通知消息", mNotificationShow);
        if (mNotificationShow) {
            mNotification = EditorGUILayout.TextField (mNotification);
            if (GUILayout.Button ("显示消息")) {
                this.ShowNotification (new GUIContent (mNotification));
            }
            if (GUILayout.Button ("隐藏消息")) {
                RemoveNotification ();
            }
        }
        EditorGUILayout.EndToggleGroup ();
        #endregion
    }
}
效果如下:


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容