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

作者: 白九a | 来源:发表于2016-12-22 21:42 被阅读146次

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

    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
        }
    }
    
    效果如下:


    相关文章

      网友评论

        本文标题:Unity编辑器开关控制显示隐藏

        本文链接:https://www.haomeiwen.com/subject/jkmhvttx.html