> For AI agents: the complete documentation index is available at /AchUtils/en/llms.txt, the full documentation bundle is available at /AchUtils/en/llms-full.txt.

# sequence

﻿# Sequence System

Build gameplay presentation flows as **declarative step lists** instead of deeply nested coroutines.

## Structure

```text
SequenceAsset (ScriptableObject)
  [SerializeReference] List<SequenceStep>

SequenceRunner (MonoBehaviour)
  - Runs steps in order as coroutines

SequenceStep (abstract, [Serializable])
  - Base class for custom steps
```

## Built-In Steps

| Step           | Description                                    |
| -------------- | ---------------------------------------------- |
| `WaitStep`     | Waits for N seconds                            |
| `MoveStep`     | Moves a Transform to a destination with easing |
| `FadeStep`     | Animates CanvasGroup alpha                     |
| `ScaleStep`    | Animates Transform scale                       |
| `SoundStep`    | Plays an AudioClip                             |
| `CallbackStep` | Invokes a UnityEvent                           |

## Quick Start

### Option A: SequenceAsset

**Create -> AchUtils/Sequence/Sequence Asset**

Add steps in the inspector, then run the asset:

```csharp
using AchUtils.Sequence;

[SerializeField] SequenceAsset introSequence;
[SerializeField] SequenceRunner runner;

void PlayIntro()
{
    runner.Run(introSequence);
}
```

### Option B: Build in Code

```csharp
var steps = new List<SequenceStep>
{
    new FadeStep  { Target = overlay,    TargetAlpha = 1f, Duration = 0.3f },
    new WaitStep  { Duration = 0.5f },
    new MoveStep  { Target = boss,       Destination = centerPos, Duration = 1f },
    new ScaleStep { Target = boss,       TargetScale = Vector3.one * 1.5f, Duration = 0.3f },
    new SoundStep { Clip = bossRoar },
    new FadeStep  { Target = overlay,    TargetAlpha = 0f, Duration = 0.5f },
};

runner.Run(steps);
```

## API

### SequenceRunner

```csharp
void Run(SequenceAsset asset)
void Run(IEnumerable<SequenceStep> steps)
void Stop()

bool IsRunning

event Action OnCompleted
event Action OnStopped
```

### MoveStep

```csharp
Transform       Target
Vector3         Destination
float           Duration
AnimationCurve  Ease
bool            UseLocalSpace
```

### FadeStep

```csharp
CanvasGroup     Target
float           TargetAlpha
float           Duration
AnimationCurve  Ease
```

### ScaleStep

```csharp
Transform       Target
Vector3         TargetScale
float           Duration
AnimationCurve  Ease
```

### SoundStep

```csharp
AudioClip       Clip
float           Volume
bool            WaitUntilFinished
```

`SoundStep` plays the clip at the `SequenceRunner` position and does not depend on `Camera.main`.

### CallbackStep

```csharp
UnityEvent      OnExecute
```

## Custom Steps

```csharp
[Serializable]
public class ShowPanelStep : SequenceStep
{
    public GameObject Panel;
    public float HoldDuration = 2f;

    public override IEnumerator Execute(SequenceRunner runner)
    {
        Panel.SetActive(true);
        yield return new WaitForSeconds(HoldDuration);
        Panel.SetActive(false);
    }
}
```

Add `[Serializable]` so the type can be selected through `[SerializeReference]`.

## Completion Event

```csharp
runner.OnCompleted += () =>
{
    Debug.Log("Intro sequence completed");
    StartGameplay();
};

runner.Run(introSequence);
```

## Boss Intro Example

```text
FadeStep     Overlay fade in
WaitStep     Wait 0.5s
MoveStep     Boss enters
ScaleStep    Boss scales up
SoundStep    Boss roar
FadeStep     Overlay fade out
CallbackStep Show UI
```
