DataVariantSystemDrawer

Generic Odin property drawer for DataVariantSystem<TData>. Renders a foldable box containing a variant navigation toolbar with add/remove buttons and a paginated view of the currently selected variant's data overrides.

Definition

Namespace: Paragon.Core.ScriptableFactory.Editor Assembly: Paragon.Editor.dll

[DrawerPriority(0.0, 0.0, 3000.0)]
public class DataVariantSystemDrawer<TData> : OdinValueDrawer<DataVariantSystem<TData>>
    where TData : FactorableData

Inherits: OdinValueDrawer<DataVariantSystem<TData>> (Sirenix.OdinInspector.Editor) Type Constraint: TData : FactorableData

Remarks

This drawer is the top-level editor component for the variant subsystem. It appears as the dataVariantSystem property section in the ScriptableFactoryEditor inspector.

The drawer provides three capabilities:

  1. Foldable container — A box with a foldout header labeled "Variant System" that collapses/expands the entire variant UI.

  2. Variant navigation — A toolbar showing the current variant count, left/right arrow buttons to navigate between variants, and a numeric index field for direct access. Plus (+) and minus (-) buttons add/remove variants.

  3. Override display — The currently selected variant's DataOverride is drawn using DataOverrideDrawer, which in turn renders each field override.

When any override value is modified, the drawer calls variantSystem.ClearBake() to invalidate the cached variant data, ensuring the next runtime access triggers a fresh bake.

Quick Lookup

Goal
How

Add a new variant

Click the + button in the toolbar

Remove the current variant

Click the - button in the toolbar

Navigate between variants

Use left/right arrows or type an index number

Invalidate cached variants

Happens automatically when any override value changes

Properties

variantCount

Returns the number of data overrides (variants) in the variant system.

Fields

currentVariantIndex

Zero-based index of the currently displayed variant. Updated by the variant selector navigation.

isExpanded

Controls whether the foldout is expanded. Defaults to true on initialization.

Methods

Initialize

Caches the DataVariantSystem<TData> reference and sets isExpanded to true.

DrawPropertyLayout

Main entry point called by Odin. Draws the foldable box, header toolbar, and variant overrides.

Parameter
Type
Description

label

GUIContent

Label from the serialized property. Falls back to "Variant System" if null.

DrawHeader

Draws the toolbar containing variant count label, navigation arrows, index field, and add/remove buttons.

Behavior:

  • Displays "No data variant exists." when variantCount is 0.

  • Shows the minus (-) button and variant selector when variantCount > 0.

  • Always shows the plus (+) button.

DrawVariantSelector

Draws the left/right arrow buttons and the numeric index field for variant navigation.

Behavior:

  • Left arrow is disabled when currentVariantIndex == 0.

  • Right arrow is disabled when currentVariantIndex == variantCount - 1.

  • Index field displays 1-based index (internally stores 0-based).

  • Index wraps via modulo when manually typed.

DrawDataOverrides

Draws the currently selected variant's DataOverride using its registered Odin drawer (DataOverrideDrawer). Monitors for changes via EditorGUI.BeginChangeCheck() and calls ClearBake() on change.

AddDataOverride

Creates a new DataOverride for type TData, appends it to the variant system, selects it, and marks the property tree dirty.

RemoveCurrentDataOverride

Removes the variant at currentVariantIndex, adjusts the index, and marks the property tree dirty.

Common Pitfalls

circle-exclamation
circle-exclamation

See Also

Last updated