private static int DrawBindingComponent(SerializedProperty componentPathProperty, string componentDescription, SerializedProperty updateTriggerProperty, SerializedProperty unityEventProperty, bool enableUpdateTriggers, bool resolveDataContext) { using (var changeScope = new EditorGUI.ChangeCheckScope()) { EditorGUILayout.PropertyField(componentPathProperty, new GUIContent(componentPathProperty.displayName, componentDescription)); // If the binding target changes, reset the binding update trigger (since the type of the target will determine the available update triggers) if (changeScope.changed) { updateTriggerProperty.intValue = (int)BindingUpdateTrigger.None; unityEventProperty.stringValue = null; } } Type resolvedType = PropertyBinding.GetComponentType((Component)componentPathProperty.FindPropertyRelative(nameof(PropertyBinding.ComponentPath.Component)).objectReferenceValue, resolveDataContext); bool isINotifyPropertyChanged = typeof(System.ComponentModel.INotifyPropertyChanged).IsAssignableFrom(resolvedType); // Try to set the target update trigger to a reasonable default if (updateTriggerProperty.intValue == (int)BindingUpdateTrigger.None) { if (isINotifyPropertyChanged) { updateTriggerProperty.intValue = (int)BindingUpdateTrigger.PropertyChangedEvent; } } // If the value never flows back from the target to the source, then there is no reason to pay attention to value change events on the target. int updateTriggerCount = -1; if (enableUpdateTriggers) { var dropDownMenu = new DropDownMenu(); if (isINotifyPropertyChanged) { dropDownMenu.Add(new DropDownItem { Label = "Property Changed", IsSelected = updateTriggerProperty.intValue == (int)BindingUpdateTrigger.PropertyChangedEvent, Command = () => { updateTriggerProperty.intValue = (int)BindingUpdateTrigger.PropertyChangedEvent; unityEventProperty.stringValue = null; } }); } List <DropDownItem> unityEvents = PropertyBindingEditor.GetDropUnityEventDownItems(resolvedType, unityEventProperty.stringValue, unityEvent => { unityEventProperty.stringValue = unityEvent; updateTriggerProperty.intValue = (int)BindingUpdateTrigger.UnityEvent; }).ToList(); if (dropDownMenu.ItemCount > 0 && unityEvents.Any()) { dropDownMenu.Add(new DropDownItem()); } unityEvents.ForEach(dropDownItem => dropDownMenu.Add(dropDownItem)); // Only show the update trigger dropdown if there is more than one choice if (dropDownMenu.ItemCount > 1) { using (new EditorGUI.IndentLevelScope()) { dropDownMenu.OnGUI("Event"); } if (dropDownMenu.SelectedIndex < 0) { EditorGUILayout.HelpBox($"Select an event that indicates the property has changed, or update the binding mode.", MessageType.Warning); } } updateTriggerCount = dropDownMenu.ItemCount; } return(updateTriggerCount); }