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

一直想通過切換按鈕實(shí)現(xiàn)編輯器上某些部分顯示或者隱藏的功能。今天無意中實(shí)現(xiàn)了這個(gè)功能。原理很簡(jiǎn)單,編輯器面板上看到的都是繪制上去的,那么只要在特定時(shí)候不繪制就實(shí)現(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 檢測(cè)鼠標(biāo)事件
//      wantsMouseMove = EditorGUILayout.Toggle ("Recive Movment : ", wantsMouseMove);
        wantsMouseMove = EditorGUILayout.BeginToggleGroup ("鼠標(biāo)移動(dòng)", 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)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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

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