UnityEditor學習筆記一



學習文章

Unity3D之Editor擴展學習(非常棒)


Build-in Attribute

十分有用的API:
RequireComponent
Header:添加屬性標題
Multilines:多行Text
Space:空行
Tooltip:屬性備注

其余:
HelpURL
AddComponentMenu
ContextMenu:允許添加一個命令到該組件上,你可以通過右鍵或者點擊設置圖標來調用到它(一般用於函數),且是在非運行狀態下執行該函數

自定義 Inspector 面板

Editor + OnInspectorGUI()

OnInspectorGUI主要是用於Editor擴展某一個腳本的Inspector窗口。

布局API

XXHorizontal
XXScrollView
XXToggleGroup
XXVertical
XXFadeGroup

XXField

Field翻譯成明顯更合適

BoundsField:邊界框
ColorField:用於選擇顏色,比如Material的選擇顏色域
CurveField:制作用於編輯動畫的曲線
DealyedXXField:敲擊Enter后才顯示
Int/FloatField:整數/浮點數
LabelField:制作一個標簽(通常用於顯示只讀信息)
LayerField:返回用戶選擇的層(就是常見的那個Layer)
PasswordField
PropertyField:制作一個用於SerializedProperty的屬性字段(見下)
RectField:矩陣,和Bounds不同,規定了內部的大小
TagField
TextField
EnumFlagsField:枚舉
Vector2/3/4Field:向量,通常是坐標值或四元數值
ObjectField

Make an object field. You can assign objects either by drag'n drop objects or by selecting an object using the Object Picker.Ensure that the allowSceneObjects parameter is false if the object reference is stored as part of an asset, since assets can't store references to objects in a scene.If the ObjectField is part of a custom Editor for a script component, use EditorUtility.IsPersistent() to check if the component is on an asset or a scene object.

其他

Popup:彈出選擇菜單
Foldout:通常用於創建樹或類似的文件夾結構,如果父物體折疊打開,才顯示子物體
InspectorTitlebar:制作一個檢視面板的標題欄
Slider
MinMaxSlider
SelectableLabel:制作一個可選擇標簽字段
PrefixLabel:制作一個在某些控件前面的標簽
Space:在上一個控件和跟隨的控件之間,制作一個小的空距
Toggle
HelpBox:提示框,i/w/e等屬性
DropdownButton:制作一個點擊后可以下拉內容的按鈕

OnSceneGUI 待補充

Lets the Editor handle an event in the scene view.
屬於Messages Sent屬性

自定義窗口

自定義窗口使用的絕大多數API仍與上面的類似,就是GUI GUILayout EditorGUI EditorGUILayout等等。具體的可以查看官網。

GUI 和 GUILayout 的使用區別就是能否精確控制,后者是自動布局,而前者是自主布局。至於有沒有加Editor的區別,主要就是沒加的可以操作Scene窗口,而有加的不行;但是兩者都可以Advance Editor。對於我這個月要做的項目來說,有涉及到控制Scene界面的功能,需要注意。

EditorWindow + OnGUI()

對於案例里的自定義窗口,主要就是需要繼承一個EditorWindow類,這個類可以創建浮動於整個編輯器的窗口。通常搭配的是OnGUI()來進行排版。

ScriptableWizard

另外,有一個比較少見但似乎很好用的,類似EditorWindow的類:ScriptableWizard。介紹如下:

繼承自EditorWindow。主要用來做向導。有2個按鈕,一個是Create,另一個是Other,有興趣的朋友可以看參考文章
OnWizardUpdate OnWizardCreate OnWizardOtherButton
優點:有定制功能,並且永遠處於最上層顯示
如果有EditorWindow想要最上層顯示的話,把繼承EditorWindow直接換成ScriptableWizard,把 MyWinClass window = (MyWinClass)EditorWindow.GetWindow (typeof(MyWinClass)); 替換為 ScriptableWizard.DisplayWizard<MyWinClass>("Title");
即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM