# Using FlowPlayer

***

## Adding to Scene

1. Select a GameObject or create a new one
2. **Add Component > FlowOfAction > FlowPlayer**

***

## Inspector Sections

### Player Settings

| Property                       | Description                                                                                                                             |
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| Auto Play                      | When to automatically start: Off, On Start, On Enable                                                                                   |
| Play Mode                      | Sequential (one after another) or Parallel (all at once)                                                                                |
| Play Direction                 | **TopToBottom**: executes from index 0 down to the last action (default). **BottomToTop**: executes from the last action up to index 0. |
| Reset On Enable                | Reset the flow state when GameObject is enabled                                                                                         |
| Delay Before Play              | Wait time before starting execution                                                                                                     |
| Loop                           | Enable looping playback                                                                                                                 |
| Number Of Loop                 | How many times to loop (0 = infinite)                                                                                                   |
| Consider Complete If No Action | Fire OnComplete even when the action list is empty (default: true)                                                                      |

### Action Flow

This section displays all actions in the sequence. Use the dropdown button to add new actions.

**Action Controls:**

* **Toggle checkbox** — Enable/disable individual actions
* **Expand/Collapse** — Click the foldout to show action properties
* **Move Up/Down (▲/▼)** — Reorder actions in the sequence
* **Remove (✕)** — Delete the action from the sequence
* **Context Menu (⋮)** — Access additional options (Copy, Duplicate, Paste, Edit Script)

**Action Header Display:**

Actions display their type name by default. If you provide a **Description** for an action, it will be shown instead of the type name, making it easier to identify actions in complex sequences.

### Events

| Event            | When Fired                                        |
| ---------------- | ------------------------------------------------- |
| OnPlay           | When Play() is called                             |
| OnPause          | When Pause() is called                            |
| OnResume         | When Resume() is called                           |
| OnStop           | When Stop() is called                             |
| OnComplete       | When the entire sequence finishes                 |
| OnActionExecuted | After each action completes (passes action index) |

***

## Editor Features

### Context Menu

Each action has a context menu button (⋮) that provides:

* **Copy** — Copies the action to clipboard for pasting elsewhere
* **Duplicate** — Creates an identical copy of the action immediately after
* **Paste Before/After** — Pastes a previously copied action before or after the current action
* **Edit Script** — Opens the action's source script in your default code editor
* **Copy All / Paste All** — Copies or pastes the entire action list; clipboard is shared between FlowPlayer and ActionFlowPreset inspectors

### Play Mode Visualization

During Play mode, the FlowPlayer inspector provides real-time feedback:

* **Currently executing action** is highlighted with a yellow/gold accent bar and background
* A **▶** symbol appears next to the action name while it's executing
* The **progress bar** in Runtime Controls shows overall sequence progress
* The inspector automatically repaints to keep the display current

### Collapse All / Expand All

Below the action list, two buttons allow you to:

* **Collapse All** — Close all action foldouts for a compact view
* **Expand All** — Open all action foldouts to see all properties at once

***

## Scripting API

```csharp
using FlowOfAction;

public class MyScript : MonoBehaviour
{
    public FlowPlayer flowPlayer;

    void Start()
    {
        // Subscribe to events
        flowPlayer.OnComplete.AddListener(OnFlowComplete);
        flowPlayer.OnActionExecuted.AddListener(OnActionDone);
    }

    public void StartSequence()  { flowPlayer.Play(); }
    public void PauseSequence()  { flowPlayer.Pause(); }
    public void ResumeSequence() { flowPlayer.Resume(); }
    public void StopSequence()   { flowPlayer.Stop(); }
    public void RestartSequence(){ flowPlayer.Restart(); }

    void OnFlowComplete()
    {
        Debug.Log("Flow completed!");
    }

    void OnActionDone(int actionIndex)
    {
        Debug.Log($"Action {actionIndex} completed");
    }
}
```

### Runtime Properties

```csharp
bool isPlaying  = flowPlayer.IsExecuting;
int  current    = flowPlayer.CurrentActionIndex;
int  total      = flowPlayer.TotalActions;
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://beelabs-dev.gitbook.io/beelabs-docs/flow-of-action/flow-player.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
