/************************************************************************************************************************/ /// <summary>Adds a menu function to assign a new instance of the `newType` to the `property`.</summary> private static void AddTypeSelector(GenericMenu menu, SerializedProperty property, Type fieldType, Type selectedType, Type newType) { var label = GetSelectorLabel(fieldType, newType); var state = selectedType == newType ? MenuFunctionState.Selected : MenuFunctionState.Normal; menu.AddPropertyModifierFunction(property, label, state, (targetProperty) => { var oldValue = property.GetValue(); var newValue = CreateDefaultInstance(newType); if (newValue is IPolymorphicReset reset) { reset.Reset(); } CopyCommonFields(oldValue, newValue); targetProperty.managedReferenceValue = newValue; targetProperty.isExpanded = true; }); }