@@ -2470,86 +2470,96 @@ internal static GenericMenu FillPropertyContextMenu(SerializedProperty property,
24702470 if ( ! property . serializedObject . targetObjects [ icount ] )
24712471 return null ;
24722472 }
2473+
24732474 // Since the menu items are invoked with delay, we can't assume a SerializedObject we don't own
24742475 // will still be around at that time. Hence create our own copy. (case 1051734)
24752476 SerializedObject serializedObjectCopy = new SerializedObject ( property . serializedObject . targetObjects ) ;
24762477 SerializedProperty propertyWithPath = serializedObjectCopy . FindProperty ( property . propertyPath ) ;
2477- ScriptAttributeUtility . GetHandler ( property ) . AddMenuItems ( property , pm ) ;
24782478
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 )
24812482 {
2482- linkedPropertyWithPath = serializedObjectCopy . FindProperty ( linkedProperty . propertyPath ) ;
2483- ScriptAttributeUtility . GetHandler ( linkedProperty ) . AddMenuItems ( linkedProperty , pm ) ;
2484- }
2483+ ScriptAttributeUtility . GetHandler ( property ) . AddMenuItems ( property , pm ) ;
24852484
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+ }
24922491
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+ }
24962498
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 ;
25022502
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 } ;
25262508
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+ }
25322532
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 )
25342535 {
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 )
25362540 {
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 ) ;
25382556 }
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 ) ;
25492557 }
25502558 }
25512559
25522560 // 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.
25532563 if ( Event . current . shift )
25542564 {
25552565 if ( pm . GetItemCount ( ) > 0 )
@@ -2558,6 +2568,8 @@ internal static GenericMenu FillPropertyContextMenu(SerializedProperty property,
25582568 }
25592569
25602570 // 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.
25612573 if ( propertyWithPath . propertyType == SerializedPropertyType . ObjectReference && Provider . isActive )
25622574 {
25632575 var obj = propertyWithPath . objectReferenceValue ;
@@ -2573,13 +2585,20 @@ internal static GenericMenu FillPropertyContextMenu(SerializedProperty property,
25732585 }
25742586 }
25752587
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 )
25772591 {
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+ }
25812598 }
25822599
2600+ EditorGUIUtility . ContextualPropertyMenuCallback ( pm , property ) ;
2601+
25832602 return pm ;
25842603 }
25852604
@@ -5768,6 +5787,8 @@ internal static GUIContent BeginPropertyInternal(Rect totalPosition, GUIContent
57685787
57695788 s_PropertyStack . Push ( new PropertyGUIData ( property , totalPosition , wasBoldDefaultFont , GUI . enabled , GUI . backgroundColor ) ) ;
57705789
5790+ EditorGUIUtility . BeginPropertyCallback ( totalPosition , property ) ;
5791+
57715792 if ( GUIDebugger . active && Event . current . type != EventType . Layout )
57725793 {
57735794 var targetObjectTypeName = property . serializedObject . targetObject != null ?
@@ -5830,13 +5851,17 @@ public static void EndProperty()
58305851 // Handle context menu in EndProperty instead of BeginProperty. This ensures that child properties
58315852 // get the event rather than parent properties when clicking inside the child property rects, but the menu can
58325853 // 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.
58335856 if ( Event . current . type == EventType . ContextClick && data . totalPosition . Contains ( Event . current . mousePosition ) )
58345857 {
5858+ GUI . enabled = oldEnable ;
58355859 if ( linkedProperties )
58365860 DoPropertyContextMenu ( data . property , parentData . property ) ;
58375861 else
58385862 DoPropertyContextMenu ( data . property ) ;
58395863 }
5864+ GUI . enabled = oldEnable ;
58405865
58415866 EditorGUIUtility . SetBoldDefaultFont ( data . wasBoldDefaultFont ) ;
58425867 GUI . enabled = data . wasEnabled ;
0 commit comments