AgentSkillsCN

odin-inspector

遵循 Odin Inspector 的验证、布局与资产管理原则。

SKILL.md
--- frontmatter
name: odin-inspector
description: Odin Inspector validation, layout, and asset management principles.
allowed-tools: Read, Write, Edit
version: 1.0
priority: HIGH

Odin Inspector Standards

Use Odin Inspector to enhance the Unity Editor experience, ensure data integrity, and provide a clear UI for designers.


🛑 Validation Attributes (MANDATORY)

Validation attributes prevent runtime errors by catching missing dependencies or invalid data in the Editor.

AttributeUse CaseExample
[Required]Mandatory reference (Prefab, Component, ScriptableObject)[Required] public GameObject Prefab;
[AssetsOnly]Field must be an Asset (Prefab/SO), NOT a scene object[AssetsOnly] public AttackDefinition Data;
[SceneObjectsOnly]Field must be in the Scene (Manager, UI Element)[SceneObjectsOnly] public Transform SpawnPoint;
[ValidateInput]Custom logical validation[ValidateInput("ValidateRange", "Range must be positive")]
[InfoBox]Provide context or warnings to designers[InfoBox("This attack scales with Level")]

🎨 Layout & Organization

Keep the Inspector clean and scannable by grouping related fields.

GroupingDescription
[BoxGroup]Wrap fields in a titled box
[HorizontalGroup]Place fields side-by-side
[TabGroup]Organize data into tabs (Impact, Visual, Audio)
[FoldoutGroup]Hide advanced settings by default
[Title]Add a clear header above a section

📁 Asset Management

Enhance asset picking and visualization.

AttributeDescription
[AssetList]Show a list of all matching assets in the project
[ValueDropdown]Provide a dropdown of valid string keys or assets
[InlineEditor]Preview and edit the referenced asset (SO) within the current inspector
[FilePath]Pick a file relative to the project
[FolderPath]Pick a directory

🚀 Best Practices

  1. Safety First: Use [AssetsOnly] whenever a field is intended for a Prefab. This prevents the "Prefab referencing Scene Object" bug which causes missing references when the scene changes.
  2. Designer Experience: Use [BoxGroup] and [HorizontalGroup] to minimize scrolling.
  3. Meaningful Error Messages: When using [ValidateInput], provide clear instructions on how to fix the error.
  4. Auto-Discovery: Use [ValueDropdown] with a helper method to list available entries (e.g., Audio Keys, Scene Names).

Verification

Before finalizing an Inspector-heavy class:

  • Are all critical references marked [Required]?
  • Are project assets constrained with [AssetsOnly]?
  • Is the layout organized into meaningful groups?
  • Do [ValueDropdown] methods return valid options?