17
17
using Event = UnityEngine . Event ;
18
18
using UnityEditor . Build ;
19
19
using UnityEditor . StyleSheets ;
20
+ using UnityEditor . VersionControl ;
20
21
using UnityEngine . Internal ;
21
22
22
23
namespace UnityEditor
@@ -553,27 +554,28 @@ public void SendEvent()
553
554
}
554
555
}
555
556
556
- private static void ShowTextEditorPopupMenu ( )
557
+ static void ShowTextEditorPopupMenu ( )
557
558
{
558
559
GenericMenu pm = new GenericMenu ( ) ;
559
- if ( s_RecycledEditor . hasSelection && ! s_RecycledEditor . isPasswordField )
560
+ var enabled = GUI . enabled ;
561
+
562
+ // Cut
563
+ if ( RecycledTextEditor . s_AllowContextCutOrPaste )
560
564
{
561
- if ( RecycledTextEditor . s_AllowContextCutOrPaste )
562
- {
565
+ if ( s_RecycledEditor . hasSelection && ! s_RecycledEditor . isPasswordField && enabled )
563
566
pm . AddItem ( EditorGUIUtility . TrTextContent ( "Cut" ) , false , new PopupMenuEvent ( EventCommandNames . Cut , GUIView . current ) . SendEvent ) ;
564
- }
565
- pm . AddItem ( EditorGUIUtility . TrTextContent ( "Copy" ) , false , new PopupMenuEvent ( EventCommandNames . Copy , GUIView . current ) . SendEvent ) ;
567
+ else
568
+ pm . AddDisabledItem ( EditorGUIUtility . TrTextContent ( "Cut" ) ) ;
566
569
}
570
+
571
+ // Copy -- when GUI is disabled, allow Copy even with no selection (will copy everything)
572
+ if ( ( s_RecycledEditor . hasSelection || ! enabled ) && ! s_RecycledEditor . isPasswordField )
573
+ pm . AddItem ( EditorGUIUtility . TrTextContent ( "Copy" ) , false , new PopupMenuEvent ( EventCommandNames . Copy , GUIView . current ) . SendEvent ) ;
567
574
else
568
- {
569
- if ( RecycledTextEditor . s_AllowContextCutOrPaste )
570
- {
571
- pm . AddDisabledItem ( EditorGUIUtility . TrTextContent ( "Cut" ) ) ;
572
- }
573
575
pm . AddDisabledItem ( EditorGUIUtility . TrTextContent ( "Copy" ) ) ;
574
- }
575
576
576
- if ( s_RecycledEditor . CanPaste ( ) && RecycledTextEditor . s_AllowContextCutOrPaste )
577
+ // Paste
578
+ if ( s_RecycledEditor . CanPaste ( ) && RecycledTextEditor . s_AllowContextCutOrPaste && enabled )
577
579
{
578
580
pm . AddItem ( EditorGUIUtility . TrTextContent ( "Paste" ) , false , new PopupMenuEvent ( EventCommandNames . Paste , GUIView . current ) . SendEvent ) ;
579
581
}
@@ -742,6 +744,34 @@ static bool MightBePrintableKey(Event evt)
742
744
}
743
745
}
744
746
747
+ static EventType GetEventTypeForControlAllowDisabledContextMenuPaste ( Event evt , int id )
748
+ {
749
+ // UI is enabled: regular code path
750
+ var wasEnabled = GUI . enabled ;
751
+ if ( wasEnabled )
752
+ return evt . GetTypeForControl ( id ) ;
753
+
754
+ // UI is disabled: get type as if it was enabled
755
+ GUI . enabled = true ;
756
+ var type = evt . GetTypeForControl ( id ) ;
757
+ GUI . enabled = false ;
758
+
759
+ // these events are always processed, no matter the enabled/disabled state (IMGUI::GetEventType)
760
+ if ( type == EventType . Repaint || type == EventType . Layout || type == EventType . Used )
761
+ return type ;
762
+
763
+ // allow context / right click, and "Copy" commands
764
+ if ( type == EventType . ContextClick )
765
+ return type ;
766
+ if ( type == EventType . MouseDown && evt . button == 1 )
767
+ return type ;
768
+ if ( ( type == EventType . ValidateCommand || type == EventType . ExecuteCommand ) && evt . commandName == EventCommandNames . Copy )
769
+ return type ;
770
+
771
+ // ignore all other events for disabled controls
772
+ return EventType . Ignore ;
773
+ }
774
+
745
775
// Should we select all text from the current field when the mouse goes up?
746
776
// (We need to keep track of this to support both SwipeSelection & initial click selects all)
747
777
internal static string DoTextField ( RecycledTextEditor editor , int id , Rect position , string text , GUIStyle style , string allowedletters , out bool changed , bool reset , bool multiline , bool passwordField )
@@ -806,7 +836,9 @@ internal static string DoTextField(RecycledTextEditor editor, int id, Rect posit
806
836
bool mayHaveChanged = false ;
807
837
string textBeforeKey = editor . text ;
808
838
809
- switch ( evt . GetTypeForControl ( id ) )
839
+ var wasEnabled = GUI . enabled ;
840
+
841
+ switch ( GetEventTypeForControlAllowDisabledContextMenuPaste ( evt , id ) )
810
842
{
811
843
case EventType . ValidateCommand :
812
844
if ( GUIUtility . keyboardControl == id )
@@ -853,7 +885,10 @@ internal static string DoTextField(RecycledTextEditor editor, int id, Rect posit
853
885
mayHaveChanged = true ;
854
886
break ;
855
887
case EventCommandNames . Copy :
856
- editor . Copy ( ) ;
888
+ if ( wasEnabled )
889
+ editor . Copy ( ) ;
890
+ else if ( ! passwordField )
891
+ GUIUtility . systemCopyBuffer = text ;
857
892
evt . Use ( ) ;
858
893
break ;
859
894
case EventCommandNames . Paste :
@@ -1007,8 +1042,11 @@ internal static string DoTextField(RecycledTextEditor editor, int id, Rect posit
1007
1042
if ( ! editor . IsEditingControl ( id ) )
1008
1043
{ // First click: focus before showing popup
1009
1044
GUIUtility . keyboardControl = id ;
1010
- editor . BeginEditing ( id , text , position , style , multiline , passwordField ) ;
1011
- editor . MoveCursorToPosition ( Event . current . mousePosition ) ;
1045
+ if ( wasEnabled )
1046
+ {
1047
+ editor . BeginEditing ( id , text , position , style , multiline , passwordField ) ;
1048
+ editor . MoveCursorToPosition ( Event . current . mousePosition ) ;
1049
+ }
1012
1050
}
1013
1051
ShowTextEditorPopupMenu ( ) ;
1014
1052
Event . current . Use ( ) ;
@@ -2492,18 +2530,30 @@ internal static GenericMenu FillPropertyContextMenu(SerializedProperty property,
2492
2530
if ( Event . current . shift )
2493
2531
{
2494
2532
if ( pm . GetItemCount ( ) > 0 )
2495
- {
2496
2533
pm . AddSeparator ( "" ) ;
2497
- }
2498
2534
pm . AddItem ( EditorGUIUtility . TrTextContent ( "Print Property Path" ) , false , e => Debug . Log ( ( ( SerializedProperty ) e ) . propertyPath ) , propertyWithPath ) ;
2499
2535
}
2500
2536
2537
+ // If property is a reference and we're using VCS, add item to check it out
2538
+ if ( propertyWithPath . propertyType == SerializedPropertyType . ObjectReference && Provider . isActive )
2539
+ {
2540
+ var obj = propertyWithPath . objectReferenceValue ;
2541
+ if ( obj != null && ! AssetDatabase . IsOpenForEdit ( obj ) )
2542
+ {
2543
+ if ( pm . GetItemCount ( ) > 0 )
2544
+ pm . AddSeparator ( "" ) ;
2545
+ pm . AddItem (
2546
+ new GUIContent ( L10n . Tr ( "Check Out" ) + " '" + obj . name + "'" ) ,
2547
+ false ,
2548
+ o => AssetDatabase . MakeEditable ( AssetDatabase . GetAssetOrScenePath ( ( Object ) o ) ) ,
2549
+ obj ) ;
2550
+ }
2551
+ }
2552
+
2501
2553
if ( EditorApplication . contextualPropertyMenu != null )
2502
2554
{
2503
2555
if ( pm . GetItemCount ( ) > 0 )
2504
- {
2505
2556
pm . AddSeparator ( "" ) ;
2506
- }
2507
2557
EditorApplication . contextualPropertyMenu ( pm , property ) ;
2508
2558
}
2509
2559
@@ -3919,7 +3969,10 @@ private static Rect RectFieldNoIndent(Rect position, Rect value)
3919
3969
s_Vector2Floats [ 0 ] = value . x ;
3920
3970
s_Vector2Floats [ 1 ] = value . y ;
3921
3971
BeginChangeCheck ( ) ;
3922
- MultiFloatField ( position , s_XYLabels , s_Vector2Floats ) ;
3972
+ // Right align the text
3973
+ var oldAlignment = EditorStyles . label . alignment ;
3974
+ EditorStyles . label . alignment = TextAnchor . MiddleRight ;
3975
+ MultiFloatFieldInternal ( position , s_XYLabels , s_Vector2Floats , kMiniLabelW ) ;
3923
3976
if ( EndChangeCheck ( ) )
3924
3977
{
3925
3978
value . x = s_Vector2Floats [ 0 ] ;
@@ -3929,12 +3982,13 @@ private static Rect RectFieldNoIndent(Rect position, Rect value)
3929
3982
s_Vector2Floats [ 0 ] = value . width ;
3930
3983
s_Vector2Floats [ 1 ] = value . height ;
3931
3984
BeginChangeCheck ( ) ;
3932
- MultiFloatField ( position , s_WHLabels , s_Vector2Floats ) ;
3985
+ MultiFloatFieldInternal ( position , s_WHLabels , s_Vector2Floats , kMiniLabelW ) ;
3933
3986
if ( EndChangeCheck ( ) )
3934
3987
{
3935
3988
value . width = s_Vector2Floats [ 0 ] ;
3936
3989
value . height = s_Vector2Floats [ 1 ] ;
3937
3990
}
3991
+ EditorStyles . label . alignment = oldAlignment ;
3938
3992
return value ;
3939
3993
}
3940
3994
@@ -4170,7 +4224,7 @@ public static void MultiFloatField(Rect position, GUIContent[] subLabels, float[
4170
4224
MultiFloatFieldInternal ( position , subLabels , values ) ;
4171
4225
}
4172
4226
4173
- internal static void MultiFloatFieldInternal ( Rect position , GUIContent [ ] subLabels , float [ ] values )
4227
+ internal static void MultiFloatFieldInternal ( Rect position , GUIContent [ ] subLabels , float [ ] values , float prefixLabelWidth = - 1 )
4174
4228
{
4175
4229
int eCount = values . Length ;
4176
4230
float w = ( position . width - ( eCount - 1 ) * kSpacingSubLabel ) / eCount ;
@@ -4180,7 +4234,7 @@ internal static void MultiFloatFieldInternal(Rect position, GUIContent[] subLabe
4180
4234
indentLevel = 0 ;
4181
4235
for ( int i = 0 ; i < values . Length ; i ++ )
4182
4236
{
4183
- EditorGUIUtility . labelWidth = EditorGUI . CalcPrefixLabelWidth ( subLabels [ i ] ) ;
4237
+ EditorGUIUtility . labelWidth = prefixLabelWidth > 0 ? prefixLabelWidth : EditorGUI . CalcPrefixLabelWidth ( subLabels [ i ] ) ;
4184
4238
values [ i ] = FloatField ( nr , subLabels [ i ] , values [ i ] ) ;
4185
4239
nr . x += w + kSpacingSubLabel ;
4186
4240
}
@@ -4361,7 +4415,10 @@ private static Color DoColorField(Rect position, int id, Color value, bool showE
4361
4415
bool hovered = position . Contains ( evt . mousePosition ) ;
4362
4416
bool hoveredEyedropper = new Rect ( position . x + position . width - kEyedropperSize , position . y , kEyedropperSize , position . height ) . Contains ( evt . mousePosition ) ;
4363
4417
4364
- switch ( evt . GetTypeForControl ( id ) )
4418
+ var wasEnabled = GUI . enabled ;
4419
+ var eventType = GetEventTypeForControlAllowDisabledContextMenuPaste ( evt , id ) ;
4420
+
4421
+ switch ( eventType )
4365
4422
{
4366
4423
case EventType . MouseDown :
4367
4424
if ( showEyedropper )
@@ -4387,7 +4444,7 @@ private static Color DoColorField(Rect position, int id, Color value, bool showE
4387
4444
GUIUtility . keyboardControl = id ;
4388
4445
4389
4446
var names = new [ ] { L10n . Tr ( "Copy" ) , L10n . Tr ( "Paste" ) } ;
4390
- var enabled = new [ ] { true , ColorClipboard . HasColor ( ) } ;
4447
+ var enabled = new [ ] { true , wasEnabled && ColorClipboard . HasColor ( ) } ;
4391
4448
var currentView = GUIView . current ;
4392
4449
4393
4450
EditorUtility . DisplayCustomMenu (
@@ -4415,7 +4472,7 @@ private static Color DoColorField(Rect position, int id, Color value, bool showE
4415
4472
4416
4473
if ( showEyedropper )
4417
4474
{
4418
- if ( hoveredEyedropper )
4475
+ if ( hoveredEyedropper && wasEnabled )
4419
4476
{
4420
4477
GUIUtility . keyboardControl = id ;
4421
4478
EyeDropper . Start ( GUIView . current ) ;
0 commit comments