EditorWindow 類

EditorWindow類,繼承 ScriptableObject,用於創建一個編輯器窗口,通常用 MenuItem 打開編輯器窗口


1、Static Properties

靜態屬性 說明
focusedWindow (沒啥用) 當前具有鍵盤焦點的EditorWindow實例(可以爲null)(只讀)
mouseOverWindow (沒啥用) 當前在鼠標光標下的EditorWindow實例(可以爲null)(只讀)
public static EditorWindow focusedWindow; 
public static EditorWindow mouseOverWindow; 

2、Properties

屬性 說明
autoRepaintOnSceneChange bool類型,當場景發生變化時,窗口是否自動重新繪製
maximized bool類型,可讀可寫,可使編輯器窗口最大化。注意當窗口undocked的時候設置該值沒有效果
maxSize / minSize Vector2類型,如果最大最小都一樣的話就可以限定窗口爲不可縮放
position Rect類型,x y width height….,座標的話是屏幕空間,左上角(0,0)
titleContent GUIContent類型,可以給編輯器指定icon、text、tooltip,如果使用icon,最好是在OnEnable(而不是構造函數中)來設置,另外可以直接在GetWindow的時候指定編輯器窗口名稱
wantsMouseEnterLeaveWindow 略 bool 檢查MouseEnterWindow和MouseLeaveWindow事件是否在此編輯器窗口的GUI中接收(不理)
wantsMouseMove(略) bool 檢查在這個編輯器窗口的GUI中是否接收了MouseMove事件(不理)

titleContent


3、public methods

公共方法 說明
BeginWindows 用於開始繪製子窗口
EndWindows 用於結束繪製子窗口
Close 用於關閉這個編輯器窗口
Focus 調用這個函數的窗口實例獲取鍵盤焦點
ShowNotification 顯示一個信息,注意該函數參數爲 GUIContent
RemoveNotification notification信息會自動fade,而這個函數可以立刻移除notification
Repaint 使窗口重繪(也沒具體咋說,例子給的是在 OnInspectorUpdate 中調用 Repaint,那麼效果是自定義編輯器重繪?沒有這個的話也沒啥影響。。。)
SendEvent 將事件發送到窗口
============ (以下幾個貌似沒什麼大區別,不用理,不調用也沒啥事。。。至於是不是浮動窗口,主要看 GetWindow 函數的 utility 參數)
Show 顯示窗口
ShowAsDropDown(Rect , Vector2) 下拉行爲和樣式(無邊框,差評)
ShowAuxWindow 在輔助窗口中顯示編輯器窗口。
ShowPopup 使用彈出式框架顯示編輯器窗口。
ShowUtility 顯示爲浮動實用程序窗口(然而並沒什麼效果)

4、static methods

靜態方法 說明
FocusWindowIfItsOpen(Type) 如果窗口打開,那麼就會聚焦在這個窗口上
GetWindow 獲取窗口實例
GetWindowWithRect 獲取窗口實例,順便指定了Rect
//最主要留意一點 utility 如果設爲true,那麼會是一個 帶邊框的 windows 浮動窗口類型

public static EditorWindow GetWindow(Type t, bool utility = false, string title = null, bool focus = true); 

public static T GetWindow();
public static T GetWindow(bool utility);
public static T GetWindow(bool utility, string title);
public static T GetWindow(string title);
public static T GetWindow(string title, bool focus);
public static T GetWindow(bool utility, string title, bool focus); 

//另外一點,desiredDockNextTo 是窗口將試圖停靠的EditorWindow數組。

public static T GetWindow(params Type[] desiredDockNextTo);
public static T GetWindow(string title, params Type[] desiredDockNextTo);
public static T GetWindow(string title, bool focus, params Type[] desiredDockNextTo); 

5、Messages

這裏寫圖片描述

注意這些是消息函數,是所有EditorWindow以及其子類都會有的消息函數。。。

消息函數 說明
Awake 在打開新窗口時調用。
OnDestroy 關閉窗口時調用
OnFocus 窗口獲得鍵盤焦點時調用
OnLostFocus 當窗口失去鍵盤焦點時調用。
OnGUI 在這裏繪製窗口的內容
onHierarchyChange 有物體在hierarchy窗口中發生改變時調用
OnInspectorUpdate Inspector更新,10幀每秒,意思難道是Inspector更新一次所有窗口都會調用一次這個函數
OnProjectChange Project發生變化,就會調用
OnSelectionChange 選擇的東西發生改變就會調用
Update 在所有可見窗口上每秒調用多次
繼承的消息函數
Awake
OnDisable
OnEnable
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章