/// <summary> /// Populates a generic menu with items from all drawers for this property that implement <see cref="IDefinesGenericMenuItems"/>. /// </summary> public void PopulateGenericMenu(GenericMenu genericMenu) { if (genericMenu == null) { throw new ArgumentNullException("genericMenu"); } OdinDrawer[] drawers = DrawerLocator.GetDrawersForProperty(this); for (int i = 0; i < drawers.Length; i++) { var drawer = drawers[i] as IDefinesGenericMenuItems; if (drawer != null) { drawer.PopulateGenericMenu(this, genericMenu); } } }
/// <summary> /// Draws a property in the inspector using a given label. /// </summary> public static void DrawProperty(InspectorProperty property, GUIContent label) { if (property == null) { throw new ArgumentNullException("property"); } bool popGUIEnabled = false; try { property.PushDraw(); if ((property.RecursiveDrawDepth + InlineEditorAttributeDrawer.CurrentInlineEditorDrawDepth) > GeneralDrawerConfig.Instance.MaxRecursiveDrawDepth) { AllEditorGUI.ErrorMessageBox("The property '" + property.NiceName + "' has exceeded the maximum recursive draw depth limit of " + GeneralDrawerConfig.Instance.MaxRecursiveDrawDepth + "."); return; } if (property.ValueEntry != null && !property.SupportsPrefabModifications && property.Tree.HasPrefabs && !GUIHelper.IsDrawingDictionaryKey && (property.Info.PropertyType == PropertyType.ReferenceType || property.Info.PropertyType == PropertyType.ValueType)) { if ((property.Parent == null || property.Parent.SupportsPrefabModifications) && GeneralDrawerConfig.Instance.ShowPrefabModificationsDisabledMessage) { AllEditorGUI.InfoMessageBox("The property '" + property.NiceName + "' does not support being modified on prefab instances. (You can disable this message the general drawer config.)"); } GUIHelper.PushGUIEnabled(false); popGUIEnabled = true; } OdinDrawer[] drawers = DrawerLocator.GetDrawersForProperty(property); GUIHelper.BeginLayoutMeasuring(); { try { if (drawers.Length > 0) { bool setIsBoldState = property.ValueEntry != null && Event.current.type == EventType.Repaint; if (setIsBoldState) { var boldState = property.ValueEntry.ValueChangedFromPrefab; if (GUIHelper.IsDrawingDictionaryKey) { // Always propagate changed state down through dictionary keys boldState |= GUIHelper.IsBoldLabel; } GUIHelper.PushIsBoldLabel(boldState); } drawers[0].DrawProperty(property, label); if (setIsBoldState) { GUIHelper.PopIsBoldLabel(); } } else { if (property.Info.PropertyType == PropertyType.Method) { EditorGUILayout.LabelField(property.NiceName, "No drawers could be found for the method property '" + property.Name + "' with signature '" + property.Info.MemberInfo.GetNiceName() + "'."); } else if (property.Info.PropertyType == PropertyType.Group) { var attr = property.Info.GetAttribute <PropertyGroupAttribute>(); if (attr != null) { EditorGUILayout.LabelField(property.NiceName, "No drawers could be found for the property group '" + property.Name + "' with property group attribute type '" + attr.GetType().GetNiceName() + "'."); } else { EditorGUILayout.LabelField(property.NiceName, "No drawers could be found for the property group '" + property.Name + "'."); } } //else if (property.Info.GetAttribute<HideInInspector>() == null) //{ // EditorGUILayout.LabelField(property.NiceName, "No drawers could be found for the value property '" + property.Name + "' of type '" + property.ValueEntry.TypeOfValue.GetNiceName() + "'."); //} } } catch (Exception ex) { if (ex is ExitGUIException || ex.InnerException is ExitGUIException) { throw ex; } else { var msg = "This error occurred while being drawn by ODIN. \n" + "ODIN Property Path: " + property.Path + "\n" + "ODIN Drawer Chain: " + string.Join(", ", drawers.Select(n => n.GetType().GetNiceName()).ToArray()) + "."; Debug.LogException(new OdinPropertyException(msg, ex)); } } } if (Event.current.type != EventType.Layout) { property.LastDrawnValueRect = GUIHelper.EndLayoutMeasuring(); } } finally { property.PopDraw(); if (popGUIEnabled) { GUIHelper.PopGUIEnabled(); } } }