MuharremTozan/Agentic-Duel / .agent/skills/unity-decorator-pattern
unity-decorator-pattern
VerifiedDynamically modify object behavior by wrapping. Perfect for buffs, debuffs, and stat calculations.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 723 B |
| assets/code/Decorator.cs.txt | markdown | 1.7 KB |
| references/guide.md | markdown | 1.7 KB |
references/guide.md
View on GitHub# Decorator Pattern Guide
The Decorator Pattern allows you to add responsibilities to individual objects dynamically, without affecting other objects. In Unity, this is often used for Buffs/Debuffs or Weapon Upgrades (e.g., Fire Damage + Ice Damage + Sword Base).
## 1. The Core Idea: Wrapping
Instead of subclassing `FireSword`, `IceSword`, `FireIceSword`, you wrap the base object:
```csharp
IStatProvider damage = new SwordBase(10f); // Base: 10
damage = new FireDamage(damage); // Adds +5 => 15
damage = new PercentageBuff(damage, 0.2f); // Adds 20% => 18
```
The client code just calls `damage.GetValue()` and doesn't care how many layers deep the wrapping goes.
## 2. Choosing Your Path (Hybrid Design)
### A. The "Pro" Path (ScriptableObject Decorators - Card Game Style)
Use this for robust data-driven RPG stats or Card Games.
1. Define a `CardDefinition` SO.
2. Define a `CardDecorator` SO that holds a reference to another `CardDefinition` at runtime (or uses a `Decorate(Card c)` method).
3. **Example**: Implementing a Card Game where playing a "Fire" card onto a "Dragon" card boosts its attack.
- The `CardDecorator` class wraps the `Card` instance.
- Calls to `Play()` on the decorator execute effects *and then* call `Play()` on the wrapped card.
### B. The "Light" Path (Runtime Stat Modifiers - RPG Style)
Use this for simple math modifiers (Powerups, Potions).
1. **Interface**: Create `IStatProvider` with `GetValue()`.
2. **Base**: `StatBase` holds the initial float.
3. **Decorators**: `StatModifier` classes take an `IStatProvider` in the constructor.
4. **Usage**:
```csharp
var health = new StatBase(100f);
health = new FlatModifier(health, 50f); // +50 Potion
Debug.Log(health.GetValue()); // 150
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |