diff --git a/Plugins/InspectPlus/Editor/InspectPlusWindow.cs b/Plugins/InspectPlus/Editor/InspectPlusWindow.cs index 73cd8e9..3f03e25 100644 --- a/Plugins/InspectPlus/Editor/InspectPlusWindow.cs +++ b/Plugins/InspectPlus/Editor/InspectPlusWindow.cs @@ -400,6 +400,7 @@ private static void ContextMenuItemNewWindow( MenuCommand command ) [MenuItem( "Assets/Inspect+/Copy Value", priority = 1500 )] [MenuItem( "CONTEXT/Component/" + CONTEXT_COPY_LABEL, priority = 1450 )] [MenuItem( "CONTEXT/ScriptableObject/" + CONTEXT_COPY_LABEL, priority = 1450 )] + [MenuItem( "CONTEXT/Material/" + CONTEXT_COPY_LABEL, priority = 1450 )] private static void ContextMenuItemCopyObject( MenuCommand command ) { if( command.context ) @@ -431,7 +432,8 @@ private static void ContextMenuItemPasteObject( MenuCommand command ) { do { - sourceProperties[property.name] = property.Copy(); + if( property.name != "m_Script" ) + sourceProperties[property.name] = property.Copy(); } while( property.NextVisible( false ) ); } @@ -1479,14 +1481,16 @@ private void ShowScrollableListContentsAsPopup( List> lists ) } } ); - Rect windowPosition = position; + float windowWidth = position.width; Rect scrollableListIconRect = GUILayoutUtility.GetLastRect(); - scrollableListIconRect.position = new Vector2( windowPosition.x, scrollableListIconRect.y + windowPosition.y ); + scrollableListIconRect.x = 0f; + scrollableListIconRect.width = windowWidth; + scrollableListIconRect.position = GUIUtility.GUIToScreenPoint( scrollableListIconRect.position ); if( !InspectPlusSettings.Instance.CompactFavoritesAndHistoryLists ) scrollableListIconRect.height -= 2f; - window.ShowAsDropDown( scrollableListIconRect, new Vector2( windowPosition.width, Mathf.Min( Screen.currentResolution.height * 0.5f, allObjects.Count * ( EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing ) + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing + 5f ) ) ); + window.ShowAsDropDown( scrollableListIconRect, new Vector2( windowWidth, Mathf.Min( Screen.currentResolution.height * 0.5f, allObjects.Count * ( EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing ) + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing + 5f ) ) ); objectBrowserWindowVisible = true; } @@ -1800,7 +1804,7 @@ private static void CopyValue( object obj ) SerializedProperty prop = (SerializedProperty) obj; object clipboard = prop.CopyValue(); if( clipboard != null ) - PasteBinWindow.AddToClipboard( clipboard, prop.serializedObject.targetObject.name + "." + prop.name ); + PasteBinWindow.AddToClipboard( clipboard, string.Concat( prop.serializedObject.targetObject.name, ".", prop.serializedObject.targetObject.GetType().Name, ".", prop.name ) ); } private static void PasteValue( object obj ) diff --git a/Plugins/InspectPlus/Editor/ObjectBrowserWindow.cs b/Plugins/InspectPlus/Editor/ObjectBrowserWindow.cs index 34289c7..2869534 100644 --- a/Plugins/InspectPlus/Editor/ObjectBrowserWindow.cs +++ b/Plugins/InspectPlus/Editor/ObjectBrowserWindow.cs @@ -128,7 +128,8 @@ private void OnGUI() Rect rect = new Rect( Vector2.zero, position.size ); // Draw borders around the window - GUI.Box( rect, GUIContent.none ); + if( Event.current.type == EventType.Repaint ) + EditorStyles.helpBox.Draw( rect, false, false, false, false ); rect.height -= EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; scrollPosition = GUI.BeginScrollView( rect, scrollPosition, new Rect( 0f, 0f, rect.width, objects.Count * ( EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing ) + 5f ), false, false, GUIStyle.none, GUI.skin.verticalScrollbar ); @@ -195,15 +196,16 @@ private void OnGUI() rect.x += EditorGUIUtility.standardVerticalSpacing; rect.width -= 2f * EditorGUIUtility.standardVerticalSpacing; - float labelWidth = EditorGUIUtility.labelWidth; + float originalLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 75f; EditorGUI.BeginChangeCheck(); - sortType = (SortType) EditorGUI.EnumPopup( rect, "Sort by:", sortType, EditorStyles.toolbarDropDown ); + + sortType = (SortType) EditorGUI.EnumPopup( rect, "Sort by:", sortType ); if( EditorGUI.EndChangeCheck() ) SortObjects(); - EditorGUIUtility.labelWidth = labelWidth; + EditorGUIUtility.labelWidth = originalLabelWidth; } private void SortObjects() diff --git a/Plugins/InspectPlus/Editor/PasteBinWindow.cs b/Plugins/InspectPlus/Editor/PasteBinWindow.cs index bf7f17f..109a33d 100644 --- a/Plugins/InspectPlus/Editor/PasteBinWindow.cs +++ b/Plugins/InspectPlus/Editor/PasteBinWindow.cs @@ -13,10 +13,10 @@ public class PasteBinWindow : EditorWindow, IHasCustomMenu private const int CLIPBOARD_CAPACITY = 30; private static readonly Color activeClipboardColor = new Color32( 245, 170, 10, 255 ); - private static readonly GUILayoutOption expandWidth = GUILayout.ExpandWidth( true ); + private static GUIStyle activeClipboardBackgroundStyle; private static readonly List clipboard = new List( 4 ); - private static readonly List clipboardLabels = new List( 4 ); + private static readonly List clipboardLabels = new List( 4 ); private static PasteBinWindow mainWindow; @@ -37,7 +37,7 @@ public class PasteBinWindow : EditorWindow, IHasCustomMenu private void OnEnable() { mainWindow = this; - gradientField = typeof( EditorGUILayout ).GetMethod( "GradientField", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, new System.Type[] { typeof( string ), typeof( Gradient ), typeof( GUILayoutOption[] ) }, null ); + gradientField = typeof( EditorGUILayout ).GetMethod( "GradientField", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, new System.Type[] { typeof( GUIContent ), typeof( Gradient ), typeof( GUILayoutOption[] ) }, null ); Repaint(); } @@ -52,7 +52,7 @@ void IHasCustomMenu.AddItemsToMenu( GenericMenu menu ) menu.AddItem( new GUIContent( "Clear" ), false, ClearClipboard ); } - public static void AddToClipboard( object obj, string name ) + public static void AddToClipboard( object obj, string label ) { if( obj == null || obj.Equals( null ) ) return; @@ -64,7 +64,7 @@ public static void AddToClipboard( object obj, string name ) } clipboard.Add( obj ); - clipboardLabels.Add( name ); + clipboardLabels.Add( new GUIContent( label, label ) ); activeClipboardIndex = clipboard.Count - 1; @@ -74,6 +74,19 @@ public static void AddToClipboard( object obj, string name ) private void OnGUI() { + if( activeClipboardBackgroundStyle == null ) + { + Texture2D background = new Texture2D( 1, 1 ); + background.SetPixel( 0, 0, activeClipboardColor ); + background.Apply( false, true ); + + activeClipboardBackgroundStyle = new GUIStyle(); + activeClipboardBackgroundStyle.normal.background = background; + activeClipboardBackgroundStyle.onNormal.background = background; + } + + Event ev = Event.current; + bool originalWideMode = EditorGUIUtility.wideMode; float originalLabelWidth = EditorGUIUtility.labelWidth; @@ -87,15 +100,15 @@ private void OnGUI() for( int i = 0; i < clipboard.Count; i++ ) { - if( activeClipboardIndex == i ) + if( clipboard[i] == null || clipboard[i].Equals( null ) ) { - Rect backgroundRect = EditorGUILayout.GetControlRect( false, 0f, expandWidth ); - backgroundRect.y += EditorGUIUtility.standardVerticalSpacing; - backgroundRect.height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - - EditorGUI.DrawRect( backgroundRect, activeClipboardColor ); + RemoveClipboard( i-- ); + continue; } + if( activeClipboardIndex == i ) + GUILayout.BeginHorizontal( activeClipboardBackgroundStyle ); + if( clipboard[i] is Object ) clipboard[i] = EditorGUILayout.ObjectField( clipboardLabels[i], clipboard[i] as Object, typeof( Object ), true ); else if( clipboard[i] is long ) @@ -128,11 +141,14 @@ private void OnGUI() GUI.enabled = true; } - Event ev = Event.current; - if( ev.type == EventType.MouseDown && ev.button == 0 && ev.mousePosition.x <= EditorGUIUtility.labelWidth && GUILayoutUtility.GetLastRect().Contains( ev.mousePosition ) ) + if( activeClipboardIndex == i ) + GUILayout.EndHorizontal(); + + if( ev.type == EventType.MouseDown && ev.button == 0 && GUILayoutUtility.GetLastRect().Contains( ev.mousePosition ) ) { activeClipboardIndex = i; Repaint(); + ev.Use(); } else if( ev.type == EventType.ContextClick && GUILayoutUtility.GetLastRect().Contains( ev.mousePosition ) ) { @@ -142,11 +158,54 @@ private void OnGUI() menu.AddItem( new GUIContent( "Copy" ), false, SetActiveClipboard, j ); menu.AddItem( new GUIContent( "Remove" ), false, RemoveClipboard, j ); menu.ShowAsContext(); + + GUIUtility.keyboardControl = 0; } } EditorGUILayout.EndScrollView(); + if( ( ev.type == EventType.DragPerform || ev.type == EventType.DragUpdated ) && GUILayoutUtility.GetLastRect().Contains( ev.mousePosition ) ) + { + // Accept drag&drop + DragAndDrop.visualMode = DragAndDropVisualMode.Copy; + if( ev.type == EventType.DragPerform ) + { + DragAndDrop.AcceptDrag(); + + Object[] draggedObjects = DragAndDrop.objectReferences; + for( int i = 0; i < draggedObjects.Length; i++ ) + AddToClipboard( draggedObjects[i], "DRAG&DROP" ); + } + + ev.Use(); + } + else if( ev.type == EventType.KeyDown ) + { + // KeyCode.Delete won't be captured by PasteBinWindow if an ObjectField has keyboard focus, therefore + // there are some "GUIUtility.keyboardControl = 0;" calls here and there to remove keyboard focus + if( ev.keyCode == KeyCode.Delete ) + { + RemoveClipboard( activeClipboardIndex ); + Repaint(); + ev.Use(); + } + else if( ev.keyCode == KeyCode.UpArrow ) + { + activeClipboardIndex = Mathf.Max( 0, activeClipboardIndex - 1 ); + GUIUtility.keyboardControl = 0; + Repaint(); + ev.Use(); + } + else if( ev.keyCode == KeyCode.DownArrow ) + { + activeClipboardIndex = Mathf.Min( clipboard.Count - 1, activeClipboardIndex + 1 ); + GUIUtility.keyboardControl = 0; + Repaint(); + ev.Use(); + } + } + EditorGUIUtility.wideMode = originalWideMode; EditorGUIUtility.labelWidth = originalLabelWidth; }