Skip to content

Commit fcdef84

Browse files
committed
Optimize mode switch
1 parent 534411b commit fcdef84

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

UInspectorPlus/InspectorPlus.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ internal class InspectorPlus: EditorWindow, IHasCustomMenu {
1313
private readonly List<InspectorDrawer[]> drawers = new List<InspectorDrawer[]>();
1414
private readonly TypeMatcher typeMatcher = new TypeMatcher();
1515
private static readonly string[] searchModes = new[] { "Selected Component Members", "Types" };
16+
private static readonly string[] titles = new[] { "Inspector+", "Type Search" };
1617
private string searchText;
1718
private int searchMode = 0;
1819
private Vector2 scrollPos;
@@ -27,7 +28,7 @@ internal class InspectorPlus: EditorWindow, IHasCustomMenu {
2728
private int[] instanceIds = new int[0];
2829

2930
private void OnEnable() {
30-
titleContent = new GUIContent("Inspector+", EditorGUIUtility.FindTexture("UnityEditor.InspectorWindow"));
31+
titleContent = new GUIContent(titles[searchMode], EditorGUIUtility.FindTexture("UnityEditor.InspectorWindow"));
3132
Initialize();
3233
OnFocus();
3334
typeMatcher.OnRequestRedraw += Repaint;
@@ -62,6 +63,8 @@ private void OnGUI() {
6263
GUI.changed = false;
6364
GUILayout.Space(8);
6465
searchText = Helper.ToolbarSearchField(searchText ?? string.Empty, searchModes, ref searchMode);
66+
if(GUI.changed)
67+
UpdateTitle();
6568
GUILayout.Space(8);
6669
EditorGUI.BeginDisabledGroup(instanceIds == null || instanceIds.Length == 0 || searchMode != 0);
6770
if(GUILayout.Button(EditorGUIUtility.IconContent("TreeEditor.Trash", "Destroy Selection"),
@@ -96,13 +99,19 @@ private void OnInspectorUpdate() {
9699
}
97100

98101
private void ShowButton(Rect rect) {
99-
GUI.Toggle(rect, locked, GUIContent.none, Helper.GetGUIStyle("IN LockButton"));
100-
if(GUI.changed)
102+
EditorGUI.BeginDisabledGroup(searchMode != 0);
103+
EditorGUI.BeginChangeCheck();
104+
GUI.Toggle(rect, locked && searchMode == 0, GUIContent.none, Helper.GetGUIStyle("IN LockButton"));
105+
if(EditorGUI.EndChangeCheck())
101106
TriggerLock();
102-
GUI.changed = false;
107+
EditorGUI.EndDisabledGroup();
103108
}
104109

105110
void IHasCustomMenu.AddItemsToMenu(GenericMenu menu) {
111+
for(int i = 0; i < searchModes.Length; i++)
112+
menu.AddItem(new GUIContent(searchModes[i]), searchMode == i, ChangeSearchMode, i);
113+
if(searchMode != 0) return;
114+
menu.AddSeparator("");
106115
menu.AddItem(new GUIContent("Refresh"), false, RefreshList);
107116
if(autoUpdateValues)
108117
menu.AddDisabledItem(new GUIContent("Update Values", "Auto Updating"));
@@ -156,6 +165,16 @@ private void TriggerLock() {
156165
EditorPrefs.SetBool("inspectorplus_lock", locked);
157166
}
158167

168+
private void ChangeSearchMode(object mode) {
169+
searchMode = (int)mode;
170+
UpdateTitle();
171+
RefreshList();
172+
}
173+
174+
private void UpdateTitle() {
175+
titleContent.text = titles[searchMode];
176+
}
177+
159178
private void OnSelectionChange() {
160179
if(!locked)
161180
instanceIds = Selection.instanceIDs;

0 commit comments

Comments
 (0)