跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
设计与 UI

unity-data-driven

Unity data-driven design architecture. ScriptableObject config hierarchies, JSON data pipelines, designer handoff workflows, data versioning and migration, Inspector attributes for self-documenting configs. DECISION format: WHEN/DECISION/SCAFFOLD/GOTCHA. Based on Unity 6.3 LTS.

Nice-Wolf-Studio · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add Nice-Wolf-Studio/unity-claude-skills --skill unity-data-driven

技能说明


name: unity-data-driven description: > Unity data-driven design architecture. ScriptableObject config hierarchies, JSON data pipelines, designer handoff workflows, data versioning and migration, Inspector attributes for self-documenting configs. DECISION format: WHEN/DECISION/SCAFFOLD/GOTCHA. Based on Unity 6.3 LTS. globs:

  • "**/*.cs"
  • "**/*.asset"

Data-Driven Design -- Decision Patterns

Prerequisite skills: unity-scripting/references/scriptableobjects.md (SO creation, event channels, runtime sets, variable references), unity-editor-tools (custom inspectors, EditorWindow)

These patterns address the most common data management failure: Claude hardcodes tunable values in MonoBehaviours or uses magic numbers, making iteration and balancing painful. All game data should be designer-editable without code changes.


PATTERN: Config Data Storage Selection

WHEN: Choosing where to store game configuration (enemy stats, level layouts, loot tables)

DECISION:

  • ScriptableObject assets (default) -- Designer-editable in Inspector, type-safe, refactorable, version-controlled as YAML. Best for most game configs.
  • JSON/CSV files -- External tools generate data (spreadsheets, web tools), need modding support, or bulk editing is required. Loaded at runtime.
  • Embedded constants -- Truly fixed values (physics constants, math, protocol versions). static readonly or const.

SCAFFOLD (ScriptableObject config):

[CreateAssetMenu(fileName = "New Enemy Config", menuName = "Game/Enemy Config")]
public class EnemyConfig : ScriptableObject
{
    [Header("Stats")]
    [Min(1)] public int maxHealth = 100;
    [Range(0f, 20f)] public float moveSpeed = 5f;
    [Range(0f, 50f)] public float attackDamage = 10f;

    [Header("AI")]
    [Range(1f, 50f)] public float detectionRange = 15f;
    [Range(0.5f, 5f)] public float attackCooldown = 1.5f;

    [Header("Rewards")]
    [Min(0)] public int xpReward = 25;
    [Tooltip("Loot dropped on death. Leave empty for no loot.")]
    public LootTable lootTable;
}

// Usage in MonoBehaviour:
public class Enemy : MonoBehaviour
{
    [SerializeField] private EnemyConfig config; // Assign in Inspector

    void Awake()
    {
        // Read from config -- never hardcode values
        _health = new HealthSystem(config.maxHealth);
        _moveSpeed = config.moveSpeed;
    }
}

GOTCHA: ScriptableObject assets modified at runtime in the Editor persist those changes to disk (the .asset file is saved). In builds, runtime modifications are lost when the application exits. Never rely on runtime SO modification for save data -- use a separate save system. See unity-save-system for persistence.


PATTERN: ScriptableObject Inheritance vs Composition

WHEN: Multiple config types share base fields (all enemies have HP/speed, subtypes add flying/ranged/boss fields)

DECISION:

  • SO inheritance -- EnemyConfig : ScriptableObject, FlyingEnemyConfig : EnemyConfig. Each subtype adds its own fields. Designer sees only relevant fields per asset. Works well for 2-3 levels of hierarchy.
  • Nested [Serializable] structs (composition) -- EnemyConfig contains [SerializeField] MovementConfig movement; [SerializeField] AttackConfig attack;. Mix-and-match capabilities. Often cleaner than inheritance for wide variation.

SCAFFOLD (Composition):

[System.Serializable]
public struct MovementConfig
{
    [Range(0f, 20f)] public float speed;
    public bool canFly;
    [Tooltip("Only used if canFly is true")]
    [Range(0f, 50f)] public float flyHeight;
}

[System.Serializable]
public struct AttackConfig
{
    public AttackType type;
    [Range(0f, 100f)] public float damage;
    [Range(0.1f, 10f)] public float cooldown;
    [Range(0f, 30f)] public float range;
}

[CreateAssetMenu(fileName = "New Enemy", menuName = "Game/Enemy Config")]
public class EnemyConfig : ScriptableObject
{
    [Header("Identity")]
    public string displayName;
    [TextArea(2, 4)] public string description;

    [Header("Movement")]
    public MovementConfig movement;

    [Header("Combat")]
    public AttackConfig attack;

    [Header("Stats")]
    [Min(1)] public int maxHealth = 100;
    [Min(0)] public int xpReward = 25;
}

SCAFFOLD (Inheritance):

public abstract class EnemyConfig : ScriptableObject
{
    [Min(1)] public int maxHealth = 100;
    [Range(0f, 20f)] public float moveSpeed = 5f;
}

[CreateAssetMenu(fileName = "New Melee Enemy", menuName = "Game/Enemies/Melee")]
public class MeleeEnemyConfig : EnemyConfig
{
    [Range(0f, 50f)] public float meleeDamage = 15f;
    [Range(0.5f, 3f)] public float attackRadius = 1.5f;
}

[CreateAssetMenu(fileName = "New Ranged Enemy", menuName = "Game/Enemies/Ranged")]
public class RangedEnemyConfig : EnemyConfig
{
    [Range(0f, 50f)] public float projectileDamage = 10f;
    [Range(5f, 30f)] public float fireRange = 15f;
    public GameObject projectilePrefab;
}

GOTCHA: SO inheritance shows ALL base fields in the Inspector (no hiding). Use [HideInInspector] or a custom editor if base fields clutter the Inspector. Composition with [Serializable] structs is often cleaner because each struct can be reused across unrelated config types. [CreateAssetMenu] only works on concrete (non-abstract) ScriptableObject subclasses.


PATTERN: JSON Data Pipeline

WHEN: Loading game data from external sources (spreadsheets, web APIs, modding)

DECISION:

  • Build-time pipeline -- Convert JSON/CSV to ScriptableObject assets in an Editor script. Data is baked at build time. Designer edits spreadsheet, runs import, data becomes SO assets.
  • Runtime loading -- Load JSON from StreamingAssets or a remote URL at runtime. Supports modding, hot-reload, and server-driven config.

SCAFFOLD (Runtime JSON loading):

// Data class (plain C#, not ScriptableObject)
[System.Serializable]
public class WaveData
{
    public int waveNumber;
    public string[] enemyTypes;
    public 
阅读完整来源 ↗