Unity編輯器開關(guān)控制顯示隱藏

一直想通過切換按鈕實現(xiàn)編輯器上某些部分顯示或者隱藏的功能。今天無意中實現(xiàn)了這個功能。原理很簡單,編輯器面板上看到的都是繪制上去的,那么只要在特定時候不繪制就實現(xiàn)了這功能。

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 檢測鼠標(biāo)事件
//      wantsMouseMove = EditorGUILayout.Toggle ("Recive Movment : ", wantsMouseMove);
        wantsMouseMove = EditorGUILayout.BeginToggleGroup ("鼠標(biāo)移動", wantsMouseMove);
        if (wantsMouseMove) {
            EditorGUILayout.Vector2Field ("    鼠標(biāo)位置", 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
    }
}
效果如下:


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,036評論 25 709
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,315評論 4 61
  • 娘說,我出生時,原不是叫沈眉莊的。 在我出生那天,正值冬梅開放,父親正披了披風(fēng)在風(fēng)雪中折一枝紅梅要給懷孕的娘,剛握...
    南萱閱讀 514評論 0 1
  • 上一章:殺死那個不修仙的少年(04君子不妄動) ....................................
    悟空和孔乙己閱讀 278評論 0 0
  • 線程狀態(tài)圖 線程間的狀態(tài)轉(zhuǎn)換 新建(new):新創(chuàng)建了一個線程對象 可運行(runnable):線程對象創(chuàng)建后,其...
    NoFacePeace閱讀 380評論 0 0

友情鏈接更多精彩內(nèi)容