How dbrizov/naughtyattributes works
Project Type and Purpose
• This is a Unity Editor/Runtime extension (plugin) called “NaughtyAttributes” that augments Unity’s built-in Inspector with custom attributes, property drawers, validation, and meta-attributes.
• It is distributed as a Unity Package (via OpenUPM, Git URL, Asset Store) and includes runtime code (Core), editor-only code (Editor), sample scenes, and automated tests.
Main Components
a. Unity Host
• Unity Editor – the IDE hosting the Inspector UI and Editor APIs
• Unity Runtime – the engine runtime that executes MonoBehaviours, serializes/deserializes fields
b. NaughtyAttributes Assemblies
• Core Assembly (NaughtyAttributes.Core.asmdef)
– Defines attribute classes (DrawerAttributes, MetaAttributes, ValidatorAttributes), utilities, and interfaces (INaughtyAttribute).
– Runs both in Editor & Play mode to mark up MonoBehaviour fields.
• Editor Assembly (NaughtyAttributes.Editor.asmdef)
– Contains CustomPropertyDrawer implementations, decorator drawers, property validators, and the NaughtyInspector class hooking into UnityEditor.
– Only compiles in the Editor.
• Test Assembly (NaughtyAttributes.Test.asmdef)
– Unit/integration tests for attributes and drawers, run via Unity Test Runner in CI.
c. Samples Directory
• DemoScene & TestAssets under Assets/NaughtyAttributes/Samples to showcase each attribute in action.
d. Packaging & CI
• package.json (Asset manifest for UPM)
• GitHub Actions (ci.yml) orchestrates Unity Test Runner, linting, packaging validations.
Relationships and Interactions
• At design time, Core attribute classes are applied to user MonoBehaviour/scriptable-object fields.
• When the Inspector renders, UnityEditor invokes the Editor Assembly’s CustomPropertyDrawers, which use reflection to read attribute metadata from the Core classes.
• Drawer logic formats the UI (dropdowns, sliders, buttons, etc.), optionally invoking callbacks or validations defined in Core.
• ValidatorAttributes provide runtime/check-in-Inspector feedback, clamping or error-highlighting fields.
• CI pipeline checks that all tests in the Test Assembly pass, ensuring attribute/drawer consistency across Unity versions.
Architectural Patterns and Principles
• Separation of Concerns:
• Core defines “what” each attribute means (metadata).
• Editor defines “how” each attribute is drawn/validated (presentation).
• Attribute-Driven Design: Behavior injected via metadata and reflection rather than manual editor code per class.
• Assembly Definition Files (.asmdef): Enforce clear module boundaries and faster compilation.
• Public Package Distribution: package.json enables OpenUPM/Git/Asset Store integration.
Essential Elements
• Call out package.json and .github/workflows for distribution and CI.
• Samples as demonstration assets, not part of core execution.