Unity 自訂Editor的視窗
- 一旦他是Ediroe class,必須把Script放在專案資料夾Assets/Editor。
- namespace在UnityEditor,因此必須using UnityEditor。
最基本的WindowEditor
WindowEditor.cs
1: using UnityEngine;
2: using UnityEditor;
3: using System.Collections;
4: public class WindowEditor : EditorWindow
5: {
6: [MenuItem("Alex Tool Development/yourName")]
7: private static void showEditor()
8: {
9: }
10: }
產生EditorWindow.
1: using UnityEngine;
2: using UnityEditor;
3: using System.Collections;
4:
5:
6: public class WindowEditor : EditorWindow
7: {
8: [MenuItem("Alex Tool Development/UnitTest")]
9: private static void showEditor()
10: {
11: WindowEditor window =(WindowEditor)EditorWindow.GetWindow(typeof(WindowEditor),true,"Unit Test Window");
12:
13: }
14:
15: void OnGUI()
16: {
17: GUILayout.Label("Base Settings", EditorStyles.boldLabel);
18: }
19: }
GetWindow參數:第二個true/false,若設定為true則Editor Tab不能拖曳至其他Tab為獨立視窗。第三個string,設定視窗Title。
showEditor 判斷是否已存在,不存在則產生一個Winodw。
No comments:
Post a Comment