private static void OnPropertyContextMenu() { EditorApplication.contextualPropertyMenu += (menu, property) => { if (property.propertyType != SerializedPropertyType.Generic) { return; } var accessor = property.GetAccessor(); if (accessor == null) { return; } if (typeof(UltEventBase).IsAssignableFrom(accessor.FieldType)) { AddEventFunctions(menu, property, accessor); BoolPref.AddDisplayOptions(menu); } else if (accessor.FieldType == typeof(PersistentCall)) { AddCallClipboardItems(menu, property, accessor); BoolPref.AddDisplayOptions(menu); } }; }
/************************************************************************************************************************/ #endregion /************************************************************************************************************************/ #region Entry Point /************************************************************************************************************************/ /// <summary>Opens the menu near the specified `area`.</summary> public static void ShowMenu(Rect area) { CachedState.CopyFrom(DrawerState.Current); _CurrentMethod = CachedState.call.GetMethodSafe(); _Bindings = GetBindingFlags(); _Menu = new GenericMenu(); BoolPref.AddDisplayOptions(_Menu); Object[] targetObjects; var targets = GetObjectReferences(CachedState.TargetProperty, out targetObjects); AddCoreItems(targets); // Populate the main contents of the menu. { if (targets == null) { var serializedMethodName = CachedState.MethodNameProperty.stringValue; Type declaringType; string methodName; PersistentCall.GetMethodDetails(serializedMethodName, null, out declaringType, out methodName); // If we have no target, but do have a type, populate the menu with that type's statics. if (declaringType != null) { PopulateMenuWithStatics(targetObjects, declaringType); goto ShowMenu; } else// If we have no type either, pretend the inspected objects are the targets. { targets = targetObjects; } } // Ensure that all targets share the same type. var firstTarget = ValidateTargetsAndGetFirst(targets); if (firstTarget == null) { targets = targetObjects; firstTarget = targets[0]; } // Add menu items according to the type of the target. if (firstTarget is GameObject) { PopulateMenuForGameObject("", false, targets); } else if (firstTarget is Component) { PopulateMenuForComponent(targets); } else { PopulateMenuForObject(targets); } } ShowMenu: _Menu.DropDown(area); GC.Collect(); }