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 : FactorableDataInherits: 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:
Foldable container — A box with a foldout header labeled "Variant System" that collapses/expands the entire variant UI.
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.
Override display — The currently selected variant's
DataOverrideis 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
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.
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."whenvariantCountis0.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
Index out of range on deserialization
If the serialized dataOverrides list changes externally (e.g., via script), currentVariantIndex may exceed the new count. DrawDataOverrides guards against this by returning early when the index is out of bounds.
ClearBake is editor-only
ClearBake() is called during Inspector editing to invalidate cached variants. At runtime, variants are baked on first access. Do not rely on editor-time bake state persisting into Play Mode.
See Also
DataVariantSystem<TData> — runtime class this drawer renders
DataOverrideDrawer — drawer for individual data overrides
ScriptableFactoryEditor — parent inspector that draws this property
Variant Editor — editor subsystem overview
Last updated