Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit b95dd8b

Browse files
committed
list editor scripts in launchpad window
1 parent 24406ee commit b95dd8b

1 file changed

Lines changed: 56 additions & 21 deletions

File tree

Assets/jsb/Source/Unity/Editor/ScriptEditorWindowLauncher.cs

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ namespace QuickJS.Unity
1414

1515
public class ScriptEditorWindowLauncher : BaseEditorWindow
1616
{
17+
private int _selectedTabViewIndex;
18+
private string[] _tabViews = new string[] { "EditorWindow", "Editor", };
19+
1720
private GUIContent _scriptIcon;
18-
private Vector2 _sv;
19-
private List<JSScriptClassPathHint> _classPaths;
21+
private Vector2 _editorViewScrollPosition;
22+
private Vector2 _editorWindowViewScrollPosition;
23+
private List<JSScriptClassPathHint> _editorWindowClassPaths;
24+
private List<JSScriptClassPathHint> _editorClassPaths;
2025

2126
void Awake()
2227
{
@@ -38,11 +43,11 @@ protected override void OnEnable()
3843

3944
private void OnScriptClassPathsUpdated()
4045
{
41-
_classPaths.Clear();
42-
JSScriptFinder.GetInstance().Search(JSScriptClassType.EditorWindow, _classPaths);
46+
_editorWindowClassPaths.Clear();
47+
JSScriptFinder.GetInstance().Search(JSScriptClassType.EditorWindow, _editorWindowClassPaths);
4348
}
4449

45-
private void DrawScriptItem(Rect rect, JSScriptClassPathHint classPath)
50+
private void DrawEditorWindowScriptItem(Rect rect, JSScriptClassPathHint classPath)
4651
{
4752
var labelHeight = Math.Min(EditorStyles.label.lineHeight, rect.height);
4853
var padding = 4f;
@@ -52,7 +57,7 @@ private void DrawScriptItem(Rect rect, JSScriptClassPathHint classPath)
5257
if (buttonSize > 8f)
5358
{
5459
var buttonRect = new Rect(rect.x + (rect.width - buttonSize) * .5f, rect.y, buttonSize, buttonSize);
55-
60+
5661
if (GUI.Button(buttonRect, _scriptIcon))
5762
{
5863
EditorRuntime.ShowWindow(classPath.modulePath, classPath.className);
@@ -61,7 +66,7 @@ private void DrawScriptItem(Rect rect, JSScriptClassPathHint classPath)
6166
var labelRect = new Rect(rect.x, rect.yMax - labelHeight, rect.width, labelHeight);
6267
EditorGUI.LabelField(labelRect, name, EditorStyles.centeredGreyMiniLabel);
6368
}
64-
else
69+
else
6570
{
6671
if (GUI.Button(rect, name))
6772
{
@@ -74,30 +79,26 @@ private void Reset()
7479
{
7580
JSScriptFinder.GetInstance().ScriptClassPathsUpdated -= OnScriptClassPathsUpdated;
7681
JSScriptFinder.GetInstance().ScriptClassPathsUpdated += OnScriptClassPathsUpdated;
77-
_classPaths = new List<JSScriptClassPathHint>();
78-
JSScriptFinder.GetInstance().Search(JSScriptClassType.EditorWindow, _classPaths);
82+
_editorClassPaths = new List<JSScriptClassPathHint>();
83+
_editorWindowClassPaths = new List<JSScriptClassPathHint>();
84+
JSScriptFinder.GetInstance().Search(JSScriptClassType.CustomEditor, _editorClassPaths);
85+
JSScriptFinder.GetInstance().Search(JSScriptClassType.EditorWindow, _editorWindowClassPaths);
7986
}
8087

81-
protected override void OnPaint()
88+
private void DrawEditorWindowScripts()
8289
{
83-
if (_classPaths == null)
84-
{
85-
Reset();
86-
}
87-
88-
var size = _classPaths.Count;
89-
EditorGUILayout.HelpBox("ScriptEditorWindowLauncher is an experimental unfinished feature. it could be used to open editor windows implemented in typescript, we need this because there is no open api in Unity to dynamically create menu item at the moment.", MessageType.Warning);
90+
_editorWindowViewScrollPosition = EditorGUILayout.BeginScrollView(_editorWindowViewScrollPosition);
91+
var size = _editorWindowClassPaths.Count;
9092
EditorGUILayout.HelpBox(string.Format("{0} EditorWindow Scripts", size), MessageType.Info);
91-
92-
_sv = EditorGUILayout.BeginScrollView(_sv);
93+
GUILayout.Space(12f);
9394
var itemSize = new Vector2(120f, 80f);
9495
var rowRect = EditorGUILayout.GetControlRect(GUILayout.Height(itemSize.y));
9596
var itemRect = new Rect(rowRect.x, rowRect.y, itemSize.x, itemSize.y);
9697
for (var i = 0; i < size; i++)
9798
{
98-
var item = _classPaths[i];
99+
var item = _editorWindowClassPaths[i];
99100

100-
DrawScriptItem(itemRect, item);
101+
DrawEditorWindowScriptItem(itemRect, item);
101102
itemRect.x += itemSize.x;
102103
if (itemRect.xMax > rowRect.xMax)
103104
{
@@ -106,6 +107,40 @@ protected override void OnPaint()
106107
}
107108
}
108109
EditorGUILayout.EndScrollView();
110+
EditorGUILayout.HelpBox("ScriptEditorWindowLauncher is an experimental unfinished feature. it could be used to open editor windows implemented in typescript, we need this because there is no open api in Unity to dynamically create menu item at the moment.", MessageType.Warning);
111+
}
112+
113+
private void DrawEditorScripts()
114+
{
115+
var size = _editorClassPaths.Count;
116+
117+
_editorViewScrollPosition = EditorGUILayout.BeginScrollView(_editorViewScrollPosition);
118+
EditorGUILayout.HelpBox(string.Format("{0} Editor Scripts", size), MessageType.Info);
119+
GUILayout.Space(12f);
120+
for (var i = 0; i < size; i++)
121+
{
122+
var item = _editorClassPaths[i];
123+
124+
EditorGUILayout.LabelField(item.ToClassPath());
125+
}
126+
EditorGUILayout.EndScrollView();
127+
}
128+
129+
protected override void OnPaint()
130+
{
131+
if (_editorWindowClassPaths == null || _editorClassPaths == null)
132+
{
133+
Reset();
134+
}
135+
136+
_selectedTabViewIndex = GUILayout.Toolbar(_selectedTabViewIndex, _tabViews);
137+
GUILayout.Space(12f);
138+
switch (_selectedTabViewIndex)
139+
{
140+
case 0: DrawEditorWindowScripts(); break;
141+
case 1: DrawEditorScripts(); break;
142+
}
143+
109144
}
110145
}
111146
}

0 commit comments

Comments
 (0)