unity-decorator-pattern

Wrap Unity base stats with decorators to compute modified values at runtime.

Updated Feb 13, 2026
One-click install
npx skills add https://github.com/MuharremTozan/Ohm-Yura --skill unity-decorator-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-decorator-pattern
Source: https://github.com/MuharremTozan/Ohm-Yura/tree/main/.agents/skills/unity-decorator-pattern
Command: npx skills add https://github.com/MuharremTozan/Ohm-Yura --skill unity-decorator-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve?

Dynamically modify object behavior at runtime by wrapping base stats, enabling reusable buffs, debuffs, and composable effects without subclassing.

Core Features & Use Cases

  • Generic interface IDecorator<T> for any value type to enable layered modifiers.
  • Stat modifiers (PercentageModifier and FlatModifier) that can be stacked to compose complex effects.
  • Real-world use: apply a +20% buff and a +10 flat bonus to a base stat to compute final value in a game.

Quick Start

Create a BaseStat and wrap it with PercentageModifier and FlatModifier, then call GetValue to see the final result.

Frequently Asked Questions about unity-decorator-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I dynamically modify stats at runtime in Unity without subclassing?

You dynamically modify stats at runtime by wrapping base stat objects with decorators like PercentageModifier and FlatModifier. This approach enables composable buffs and debuffs without altering base classes, using the IDecorator<T> interface for layered value computation.

What is the decorator pattern used for in Unity stat systems?

The decorator pattern in Unity stat systems is used for dynamically modifying numeric statistics at runtime. It allows developers to stack buffs, debuffs, and damage calculations by wrapping base stats, enabling reusable and composable effects.

Can I stack multiple buffs and debuffs on a single base stat in Unity?

Yes, you can stack multiple buffs and debuffs on a single base stat. The system supports composable effects by wrapping a BaseStat with multiple PercentageModifier and FlatModifier instances, computing a deterministic final value when GetValue is called.

How do I apply a flat bonus and a percentage buff to a Unity stat?

To apply a flat bonus and a percentage buff, create a BaseStat and wrap it sequentially with PercentageModifier and FlatModifier instances. Calling GetValue computes the final result by layering the decorators over the base stat value.

Does this Unity stat modifier system require external dependencies?

No, this Unity stat modifier system does not require external dependencies. It operates independently using a generic IDecorator<T> interface along with built-in BaseStat, PercentageModifier, and FlatModifier components to calculate final values.

When should I use the decorator pattern for stat calculations instead of inheritance?

You should use the decorator pattern for stat calculations when you need to dynamically add or remove buffs and debuffs at runtime. It prevents class explosion from deep inheritance hierarchies by allowing composable stat modifiers to wrap objects individually.