protected virtual void DrawPopup(Rect rect, out Rect popupRect, int elementIndex) { Type type = Target.Components[elementIndex].GetType(); popupRect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight + POPUP_SPACING); int optionIndex = ComponentTypes.IndexOf(type); int newIndex = EditorGUI.Popup(popupRect, optionIndex, ComponentOptions); if (newIndex != optionIndex) { SwitchInstanceType(newIndex); } void SwitchInstanceType(int typeIndex) { RemoveObject(Target.Components[elementIndex]); PatternComponent newInstance = CreateComponent(typeIndex); Target.Components[elementIndex] = newInstance; AddObject(newInstance); } }