CoinDrawer
Odin Inspector value drawer for Coin fields. Renders coin values as three inline integer fields with colored denomination icons (gold, silver, copper) instead of a single raw int.
Definition
Namespace: Paragon.Townskeep Assembly: Townskeep.Editor.dll
[DrawerPriority(0.0, 0.0, 3000.0), UsedImplicitly]
public class CoinDrawer : OdinValueDrawer<Coin>Inheritance: OdinValueDrawer<Coin> → CoinDrawer
Remarks
CoinDrawer uses a high priority (3000.0) to ensure it overrides any default drawer for Coin fields. It renders a horizontal layout with:
The property label (via
DrawGUI.PrefixLabel)Three integer fields using
EditorGUI.MultiIntFieldwith colored circle icons:Gold — yellow (
#FFCC00)Silver — grey-blue (
#808099)Copper — brown (
#B3662A)
Icon textures are lazily created via SdfIcons.CreateTransparentIconTexture() and cached in a static array for reuse across all CoinDrawer instances.
When the user edits any denomination, the drawer recomputes the raw value (gold * 10000 + silver * 100 + copper), calls SetValue() on the Coin, and marks the serialization root dirty.
The drawer uses DrawGUI.HorizontalLayout() from Paragon.Editor for consistent horizontal layout rendering.
Quick Lookup
Apply to a Coin field
Automatic — drawer is registered via Odin at priority 3000
Customise icon colors
Modify GetCoinIcons() static method
Methods
DrawPropertyLayout (override)
Renders the Coin property as three inline denomination fields.
label
GUIContent
The property label from Odin
Rendering pipeline:
Begin horizontal layout
Draw prefix label
Read current Gold/Silver/Copper values from
ValueEntry.SmartValueRender
EditorGUI.MultiIntFieldwith coin iconsOn change: recompute raw value, call
SetValue(), mark dirty
GetCoinIcons (static, private)
Lazily creates and caches the three denomination icon textures.
Returns: Array of 3 GUIContent entries with colored circle icons.
Common Pitfalls
Null SmartValue The drawer guards against null ValueEntry.SmartValue with ?? 0 for each denomination. If the Coin field is null (possible with reference-type serialization), the drawer shows zeros without crashing.
Editor-only class This class exists in the Editor assembly and must not be referenced from runtime code. It is auto-discovered by Odin via the [DrawerPriority] attribute.
See Also
Last updated