/// <summary> /// Draws the enable field, custom editor display name and order field /// </summary> private void DrawLabelAndOrderField(CustomEditorExtensionSettings _Settings, Vector2 _Position, Vector2 _Size) { // Draw the enable field Vector2 position = _Position; Vector2 size = new Vector2(_Size.x - ORDER_FIELD_WIDTH - EditorHelpers.HORIZONTAL_MARGIN * 2, _Size.y); _Settings.Enabled = EditorGUI.ToggleLeft(new Rect(position, size), _Settings.DisplayName, _Settings.Enabled, m_Extended ? EditorStyles.boldLabel : EditorStyles.label); // Draw the order field position.x += size.x + EditorHelpers.HORIZONTAL_MARGIN; size.x = ORDER_FIELD_WIDTH; int orderBefore = _Settings.Order; _Settings.Order = EditorGUI.IntField(new Rect(position, size), _Settings.Order); }
/// <summary> /// Called when an element of the reorderable list is drawn. /// </summary> private void OnDrawElement(Rect _Rect, int _Index, bool _IsActive, bool _IsFocused) { EditorGUIUtility.labelWidth = LABEL_WIDTH; // Alias for settings fields being drawn CustomEditorExtensionSettings settings = m_Settings[_Index]; // Draw the enable field, custom editor display name, and order field Vector2 position = _Rect.position; position.y += EditorHelpers.VERTICAL_MARGIN; Vector2 size = new Vector2(_Rect.width, EditorGUIUtility.singleLineHeight); DrawLabelAndOrderField(settings, position, size); // If the list is not extended, stop here if (!m_Extended) { return; } // Draw the description of the custom editor position.y += size.y + EditorHelpers.VERTICAL_MARGIN; position.x += INDENTATION; size.x -= INDENTATION; GUI.Box(new Rect(position, new Vector2(size.x, DESCRIPTION_HEIGHT)), settings.Description, DescriptionFieldStyle); // Draws the "require constant repaint" option field position.y += DESCRIPTION_HEIGHT + EditorHelpers.VERTICAL_MARGIN; settings.RequiresConstantRepaint = EditorGUI.Toggle(new Rect(position, size), "Requires Constant Repaint", settings.RequiresConstantRepaint); // Draws an horizontal line if the current settings are not the last entry of the list if (_Index < m_Settings.Count - 1) { position.x -= INDENTATION + m_LeftOffset; size.x += INDENTATION + m_LeftOffset; position.y += size.y + EditorHelpers.VERTICAL_MARGIN; EditorHelpers.HorizontalLine(new Rect(position, new Vector2(size.x, 1f))); } }
/// <summary> /// Adds a new settings entry in the list, or update an existing one. /// </summary> /// <param name="_TargetType">The target type of the custom editor.</param> /// <param name="_CreateEditorMethod">The method to use to create an instance of the custom editor extension.</param> /// <param name="_DefaultOptions">The default options to use for the custom editor extension.</param> /// <returns>Returns the created settings.</returns> private CustomEditorExtensionSettings AddOrUpdateCustomEditorSettings(CreateEditorDelegate _CreateEditorMethod, Type _TargetType, CustomEditorExtensionOptions _DefaultOptions) { Type customEditorType = _CreateEditorMethod.Invoke().GetType(); // Gets the existing settings for the custom inspector. CustomEditorExtensionSettings settings = m_CustomEditorSettings.Find(currentSettings => { return(currentSettings.CustomEditorType == customEditorType); }); // Update the existing settings if it exists if (settings != null) { settings.Update(_TargetType, _CreateEditorMethod, _DefaultOptions); } // If no matching settings has been found, create a new one using the given params, and add it to the list else { settings = new CustomEditorExtensionSettings(_TargetType, customEditorType, _CreateEditorMethod, _DefaultOptions); m_CustomEditorSettings.Add(settings); } m_CustomEditorSettings.Sort(); return(settings); }