@@ -2470,86 +2470,96 @@ internal static GenericMenu FillPropertyContextMenu(SerializedProperty property,
2470
2470
if ( ! property . serializedObject . targetObjects [ icount ] )
2471
2471
return null ;
2472
2472
}
2473
+
2473
2474
// Since the menu items are invoked with delay, we can't assume a SerializedObject we don't own
2474
2475
// will still be around at that time. Hence create our own copy. (case 1051734)
2475
2476
SerializedObject serializedObjectCopy = new SerializedObject ( property . serializedObject . targetObjects ) ;
2476
2477
SerializedProperty propertyWithPath = serializedObjectCopy . FindProperty ( property . propertyPath ) ;
2477
- ScriptAttributeUtility . GetHandler ( property ) . AddMenuItems ( property , pm ) ;
2478
2478
2479
- SerializedProperty linkedPropertyWithPath = null ;
2480
- if ( linkedProperty != null )
2479
+ // FillPropertyContextMenu is now always called when a right click is done on a property.
2480
+ // However we don't want those menu to be added when the property is disabled.
2481
+ if ( GUI . enabled )
2481
2482
{
2482
- linkedPropertyWithPath = serializedObjectCopy . FindProperty ( linkedProperty . propertyPath ) ;
2483
- ScriptAttributeUtility . GetHandler ( linkedProperty ) . AddMenuItems ( linkedProperty , pm ) ;
2484
- }
2483
+ ScriptAttributeUtility . GetHandler ( property ) . AddMenuItems ( property , pm ) ;
2485
2484
2486
- // Would be nice to allow to set to value of a specific target for properties with children too,
2487
- // but it's not currently supported.
2488
- if ( property . hasMultipleDifferentValues && ! property . hasVisibleChildren )
2489
- {
2490
- TargetChoiceHandler . AddSetToValueOfTargetMenuItems ( pm , propertyWithPath , TargetChoiceHandler . SetToValueOfTarget ) ;
2491
- }
2485
+ SerializedProperty linkedPropertyWithPath = null ;
2486
+ if ( linkedProperty != null )
2487
+ {
2488
+ linkedPropertyWithPath = serializedObjectCopy . FindProperty ( linkedProperty . propertyPath ) ;
2489
+ ScriptAttributeUtility . GetHandler ( linkedProperty ) . AddMenuItems ( linkedProperty , pm ) ;
2490
+ }
2492
2491
2493
- if ( property . serializedObject . targetObjectsCount == 1 && property . isInstantiatedPrefab && property . prefabOverride )
2494
- {
2495
- Object targetObject = property . serializedObject . targetObject ;
2492
+ // Would be nice to allow to set to value of a specific target for properties with children too,
2493
+ // but it's not currently supported.
2494
+ if ( property . hasMultipleDifferentValues && ! property . hasVisibleChildren )
2495
+ {
2496
+ TargetChoiceHandler . AddSetToValueOfTargetMenuItems ( pm , propertyWithPath , TargetChoiceHandler . SetToValueOfTarget ) ;
2497
+ }
2496
2498
2497
- SerializedProperty [ ] properties ;
2498
- if ( linkedProperty == null )
2499
- properties = new SerializedProperty [ ] { propertyWithPath } ;
2500
- else
2501
- properties = new SerializedProperty [ ] { propertyWithPath , linkedPropertyWithPath } ;
2499
+ if ( property . serializedObject . targetObjectsCount == 1 && property . isInstantiatedPrefab && property . prefabOverride )
2500
+ {
2501
+ Object targetObject = property . serializedObject . targetObject ;
2502
2502
2503
- PrefabUtility . HandleApplyRevertMenuItems (
2504
- null ,
2505
- targetObject ,
2506
- ( menuItemContent , sourceObject ) =>
2507
- {
2508
- // Add apply menu item for this apply target.
2509
- TargetChoiceHandler . PropertyAndSourcePathInfo info = new TargetChoiceHandler . PropertyAndSourcePathInfo ( ) ;
2510
- info . properties = properties ;
2511
- info . assetPath = AssetDatabase . GetAssetPath ( sourceObject ) ;
2512
- GameObject rootObject = PrefabUtility . GetRootGameObject ( sourceObject ) ;
2513
- if ( ! PrefabUtility . IsPartOfPrefabThatCanBeAppliedTo ( rootObject ) || EditorUtility . IsPersistent ( targetObject ) )
2514
- pm . AddDisabledItem ( menuItemContent ) ;
2515
- else
2516
- pm . AddItem ( menuItemContent , false , TargetChoiceHandler . ApplyPrefabPropertyOverride , info ) ;
2517
- } ,
2518
- ( menuItemContent ) =>
2519
- {
2520
- // Add revert menu item.
2521
- pm . AddItem ( menuItemContent , false , TargetChoiceHandler . RevertPrefabPropertyOverride , properties ) ;
2522
- } ,
2523
- false
2524
- ) ;
2525
- }
2503
+ SerializedProperty [ ] properties ;
2504
+ if ( linkedProperty == null )
2505
+ properties = new SerializedProperty [ ] { propertyWithPath } ;
2506
+ else
2507
+ properties = new SerializedProperty [ ] { propertyWithPath , linkedPropertyWithPath } ;
2526
2508
2527
- // If property is an element in an array, show duplicate and delete menu options
2528
- if ( property . propertyPath . LastIndexOf ( ']' ) == property . propertyPath . Length - 1 )
2529
- {
2530
- var parentArrayPropertyPath = property . propertyPath . Substring ( 0 , property . propertyPath . LastIndexOf ( ".Array.data[" , StringComparison . Ordinal ) ) ;
2531
- var parentArrayProperty = property . serializedObject . FindProperty ( parentArrayPropertyPath ) ;
2509
+ PrefabUtility . HandleApplyRevertMenuItems (
2510
+ null ,
2511
+ targetObject ,
2512
+ ( menuItemContent , sourceObject ) =>
2513
+ {
2514
+ // Add apply menu item for this apply target.
2515
+ TargetChoiceHandler . PropertyAndSourcePathInfo info = new TargetChoiceHandler . PropertyAndSourcePathInfo ( ) ;
2516
+ info . properties = properties ;
2517
+ info . assetPath = AssetDatabase . GetAssetPath ( sourceObject ) ;
2518
+ GameObject rootObject = PrefabUtility . GetRootGameObject ( sourceObject ) ;
2519
+ if ( ! PrefabUtility . IsPartOfPrefabThatCanBeAppliedTo ( rootObject ) || EditorUtility . IsPersistent ( targetObject ) )
2520
+ pm . AddDisabledItem ( menuItemContent ) ;
2521
+ else
2522
+ pm . AddItem ( menuItemContent , false , TargetChoiceHandler . ApplyPrefabPropertyOverride , info ) ;
2523
+ } ,
2524
+ ( menuItemContent ) =>
2525
+ {
2526
+ // Add revert menu item.
2527
+ pm . AddItem ( menuItemContent , false , TargetChoiceHandler . RevertPrefabPropertyOverride , properties ) ;
2528
+ } ,
2529
+ false
2530
+ ) ;
2531
+ }
2532
2532
2533
- if ( ! parentArrayProperty . isFixedBuffer )
2533
+ // If property is an element in an array, show duplicate and delete menu options
2534
+ if ( property . propertyPath . LastIndexOf ( ']' ) == property . propertyPath . Length - 1 )
2534
2535
{
2535
- if ( pm . GetItemCount ( ) > 0 )
2536
+ var parentArrayPropertyPath = property . propertyPath . Substring ( 0 , property . propertyPath . LastIndexOf ( ".Array.data[" , StringComparison . Ordinal ) ) ;
2537
+ var parentArrayProperty = property . serializedObject . FindProperty ( parentArrayPropertyPath ) ;
2538
+
2539
+ if ( ! parentArrayProperty . isFixedBuffer )
2536
2540
{
2537
- pm . AddSeparator ( "" ) ;
2541
+ if ( pm . GetItemCount ( ) > 0 )
2542
+ {
2543
+ pm . AddSeparator ( "" ) ;
2544
+ }
2545
+
2546
+ pm . AddItem ( EditorGUIUtility . TrTextContent ( "Duplicate Array Element" ) , false , ( a ) =>
2547
+ {
2548
+ TargetChoiceHandler . DuplicateArrayElement ( a ) ;
2549
+ EditorGUIUtility . editingTextField = false ;
2550
+ } , propertyWithPath ) ;
2551
+ pm . AddItem ( EditorGUIUtility . TrTextContent ( "Delete Array Element" ) , false , ( a ) =>
2552
+ {
2553
+ TargetChoiceHandler . DeleteArrayElement ( a ) ;
2554
+ EditorGUIUtility . editingTextField = false ;
2555
+ } , propertyWithPath ) ;
2538
2556
}
2539
- pm . AddItem ( EditorGUIUtility . TrTextContent ( "Duplicate Array Element" ) , false , ( a ) =>
2540
- {
2541
- TargetChoiceHandler . DuplicateArrayElement ( a ) ;
2542
- EditorGUIUtility . editingTextField = false ;
2543
- } , propertyWithPath ) ;
2544
- pm . AddItem ( EditorGUIUtility . TrTextContent ( "Delete Array Element" ) , false , ( a ) =>
2545
- {
2546
- TargetChoiceHandler . DeleteArrayElement ( a ) ;
2547
- EditorGUIUtility . editingTextField = false ;
2548
- } , propertyWithPath ) ;
2549
2557
}
2550
2558
}
2551
2559
2552
2560
// If shift is held down, show debug menu options
2561
+ // This menu is not excluded when the field is disabled
2562
+ // because it is nice to get information about the property even when it's disabled.
2553
2563
if ( Event . current . shift )
2554
2564
{
2555
2565
if ( pm . GetItemCount ( ) > 0 )
@@ -2558,6 +2568,8 @@ internal static GenericMenu FillPropertyContextMenu(SerializedProperty property,
2558
2568
}
2559
2569
2560
2570
// If property is a reference and we're using VCS, add item to check it out
2571
+ // This menu is not excluded when the field is disabled
2572
+ // because it is nice to get information about the property even when it's disabled.
2561
2573
if ( propertyWithPath . propertyType == SerializedPropertyType . ObjectReference && Provider . isActive )
2562
2574
{
2563
2575
var obj = propertyWithPath . objectReferenceValue ;
@@ -2573,13 +2585,20 @@ internal static GenericMenu FillPropertyContextMenu(SerializedProperty property,
2573
2585
}
2574
2586
}
2575
2587
2576
- if ( EditorApplication . contextualPropertyMenu != null )
2588
+ // FillPropertyContextMenu is now always called when a right click is done on a property.
2589
+ // However we don't want those menu to be added when the property is disabled.
2590
+ if ( GUI . enabled )
2577
2591
{
2578
- if ( pm . GetItemCount ( ) > 0 )
2579
- pm . AddSeparator ( "" ) ;
2580
- EditorApplication . contextualPropertyMenu ( pm , property ) ;
2592
+ if ( EditorApplication . contextualPropertyMenu != null )
2593
+ {
2594
+ if ( pm . GetItemCount ( ) > 0 )
2595
+ pm . AddSeparator ( "" ) ;
2596
+ EditorApplication . contextualPropertyMenu ( pm , property ) ;
2597
+ }
2581
2598
}
2582
2599
2600
+ EditorGUIUtility . ContextualPropertyMenuCallback ( pm , property ) ;
2601
+
2583
2602
return pm ;
2584
2603
}
2585
2604
@@ -5768,6 +5787,8 @@ internal static GUIContent BeginPropertyInternal(Rect totalPosition, GUIContent
5768
5787
5769
5788
s_PropertyStack . Push ( new PropertyGUIData ( property , totalPosition , wasBoldDefaultFont , GUI . enabled , GUI . backgroundColor ) ) ;
5770
5789
5790
+ EditorGUIUtility . BeginPropertyCallback ( totalPosition , property ) ;
5791
+
5771
5792
if ( GUIDebugger . active && Event . current . type != EventType . Layout )
5772
5793
{
5773
5794
var targetObjectTypeName = property . serializedObject . targetObject != null ?
@@ -5830,13 +5851,17 @@ public static void EndProperty()
5830
5851
// Handle context menu in EndProperty instead of BeginProperty. This ensures that child properties
5831
5852
// get the event rather than parent properties when clicking inside the child property rects, but the menu can
5832
5853
// still be invoked for the parent property by clicking inside the parent rect but outside the child rects.
5854
+ var oldEnable = GUI . enabled ;
5855
+ GUI . enabled = true ; // Event.current.type will never return ContextClick if the GUI is disabled.
5833
5856
if ( Event . current . type == EventType . ContextClick && data . totalPosition . Contains ( Event . current . mousePosition ) )
5834
5857
{
5858
+ GUI . enabled = oldEnable ;
5835
5859
if ( linkedProperties )
5836
5860
DoPropertyContextMenu ( data . property , parentData . property ) ;
5837
5861
else
5838
5862
DoPropertyContextMenu ( data . property ) ;
5839
5863
}
5864
+ GUI . enabled = oldEnable ;
5840
5865
5841
5866
EditorGUIUtility . SetBoldDefaultFont ( data . wasBoldDefaultFont ) ;
5842
5867
GUI . enabled = data . wasEnabled ;
0 commit comments