Skip to content

Commit 0b23db6

Browse files
committed
Tweaked the Inspector+ menu and lock icon.
- Fixed text too-long in Inspector+.
1 parent e3b3b7e commit 0b23db6

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

Assets/Script Tester/Editor/Helpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ internal static string StringField(GUIContent label, string value, bool readOnly
279279
int length = value == null ? 0 : value.Length;
280280
if(length > 5000) {
281281
EditorGUILayout.BeginHorizontal();
282-
EditorGUILayout.LabelField(label, "Text too long to display (" + length + " characters)");
282+
EditorGUILayout.LabelField(label, new GUIContent("Text too long to display (" + length + " characters)"));
283283
if(GUILayout.Button("Copy", GUILayout.ExpandWidth(false)))
284284
EditorGUIUtility.systemCopyBuffer = value;
285285
if(!readOnly && GUILayout.Button("Paste", GUILayout.ExpandWidth(false))) {

Assets/Script Tester/Editor/InspectorPlus.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
using UnityObject = UnityEngine.Object;
99

1010
namespace ScriptTester {
11-
class InspectorPlus : EditorWindow {
11+
class InspectorPlus : EditorWindow, IHasCustomMenu {
1212
readonly List<InspectorDrawer[]> drawers = new List<InspectorDrawer[]>();
1313
string searchText;
1414
Vector2 scrollPos;
15-
Rect toolbarMenuPos;
1615
bool autoUpdateValues = EditorPrefs.GetBool("inspectorplus_autoupdate", true);
1716
bool privateFields = EditorPrefs.GetBool("inspectorplus_private", true);
1817
bool forceUpdateProps = EditorPrefs.GetBool("inspectorplus_editupdate", false);
@@ -37,10 +36,6 @@ void OnFocus() {
3736

3837
void OnGUI() {
3938
GUILayout.BeginHorizontal(EditorStyles.toolbar);
40-
if(GUILayout.Button("Menu", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
41-
ShowMenu();
42-
if(Event.current.type == EventType.Repaint)
43-
toolbarMenuPos = GUILayoutUtility.GetLastRect();
4439
GUI.changed = false;
4540
GUILayout.Space(8);
4641
searchText = EditorGUILayout.TextField(searchText, Helper.GetGUIStyle("ToolbarSeachTextField"));
@@ -72,22 +67,23 @@ void OnInspectorUpdate() {
7267
if(!autoUpdateValues || EditorGUIUtility.editingTextField)
7368
return;
7469
UpdateValues();
75-
}
76-
77-
void ShowMenu() {
78-
var menu = new GenericMenu();
70+
}
71+
72+
void ShowButton(Rect rect) {
73+
GUI.Toggle(rect, locked, GUIContent.none, Helper.GetGUIStyle("IN LockButton"));
74+
if(GUI.changed)
75+
TriggerLock();
76+
GUI.changed = false;
77+
}
78+
79+
public void AddItemsToMenu(GenericMenu menu) {
7980
menu.AddItem(new GUIContent("Refresh"), false, RefreshList);
8081
if(autoUpdateValues)
8182
menu.AddDisabledItem(new GUIContent("Update Values", "Auto Updating"));
8283
else
8384
menu.AddItem(new GUIContent("Update Values"), false, UpdateValues);
8485
menu.AddSeparator("");
85-
menu.AddItem(new GUIContent("Lock Selection"), locked, () => {
86-
locked = !locked;
87-
if(!locked)
88-
OnSelectionChange();
89-
EditorPrefs.SetBool("inspectorplus_lock", locked);
90-
});
86+
menu.AddItem(new GUIContent("Lock Selection"), locked, TriggerLock);
9187
menu.AddItem(new GUIContent("Auto Update Values"), autoUpdateValues, () => {
9288
autoUpdateValues = !autoUpdateValues;
9389
EditorPrefs.SetBool("inspectorplus_autoupdate", autoUpdateValues);
@@ -120,13 +116,19 @@ void ShowMenu() {
120116
IterateDrawers<IReflectorDrawer>(methodDrawer => methodDrawer.AllowObsolete = showObsolete);
121117
EditorPrefs.SetBool("inspectorplus_obsolete", showObsolete);
122118
});
123-
menu.DropDown(toolbarMenuPos);
124119
}
125120

126121
void RefreshList() {
127122
drawers.Clear();
128123
OnSelectionChange();
129124
}
125+
126+
void TriggerLock() {
127+
locked = !locked;
128+
if(!locked)
129+
OnSelectionChange();
130+
EditorPrefs.SetBool("inspectorplus_lock", locked);
131+
}
130132

131133
void OnSelectionChange() {
132134
if(!locked)
@@ -186,5 +188,5 @@ void UpdateValues(bool updateProps) {
186188
drawerGroup.UpdateValues(updateProps);
187189
Repaint();
188190
}
189-
}
191+
}
190192
}

0 commit comments

Comments
 (0)