88using UnityObject = UnityEngine . Object ;
99
1010namespace 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