Unity Decorator Pattern

Dynamically modify object behavior by wrapping. Perfect for buffs, debuffs, and stat calculations.

muharremtozan 1f1b0a0 3 files · 4.1 KB Updated

File contents

Unity Decorator Pattern

Minimal decorator pattern for stat modification.

Core Features

  1. Generic Interface: IDecorator<T> for any value type
  2. Stat Modifiers: Percentage and flat modifications
  3. Composable: Stack multiple decorators

Core Files (1 file)

  • Decorator.cs.txt: Complete decorator pattern (interface + base + modifiers)

Usage

IDecorator<float> damage = new BaseStat(100);
damage = new PercentageModifier(damage, 0.2f); // +20%
damage = new FlatModifier(damage, 10); // +10
float final = damage.GetValue(); // 130

muharremtozan/unity-agent-skills/tree/main/unity-decorator-pattern commit 1f1b0a0c0a

Frequently asked questions

npx skillmds@latest add muharremtozan/unity-decorator-pattern