Skip to content

MuharremTozan/Agentic-Duel / .agent/skills/unity-memento-pattern

unity-memento-pattern

Verified

Implements the Memento pattern for capturing and restoring object states. Perfect for Loadout managers, Checkpoints, and Undo/Redo systems.

references/guide.md

View on GitHub
# Memento Pattern Guide

The Memento pattern captures and restores an object's internal state without violating encapsulation. In game development, it is primarily used for **Undo/Redo systems**, **Quick-Save/Load**, and **Loadout Presets**.

## Core Components
1. **Originator**: The object that has state you want to save (e.g., Player, Hotbar). It implements `IOriginator<T>`.
2. **Memento**: The data structure (struct) that holds the snapshot.
3. **Caretaker**: The object that keeps track of the history (`StateCaretaker<T>`).

## How to Implement

### Step 1: Define the State Struct
Identify the critical variables that need to be saved.
```csharp
public struct MyState {
    public int Level;
    public string CurrentZone;
}
```

### Step 2: Implement IOriginator
On your target MonoBehaviour, implement the `CreateMemento` and `Restore` methods.

### Step 3: Manage History
Use the `StateCaretaker` to provide Undo/Redo functionality or to store multiple loadouts.

## Why Memento?
- **Decoupling**: The Caretaker doesn't need to know *what* is inside the memento, only that it can store and return it.
- **Simplicity**: No need to write complex "Reverse logic" for every command. Just go back to the previous snapshot.
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: 198kUpdated Claude CodeCodexVerifiedInstall
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: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
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: 194kUpdated Claude CodeCodexVerifiedInstall