# kh-returngame/rg2_rhythmhealth architecture

> Architecture diagram of the GitHub repository kh-returngame/rg2_rhythmhealth, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kh-returngame/rg2_rhythmhealth
- Repository: https://github.com/kh-returngame/rg2_rhythmhealth

## Overview

##### Project Type and Purpose
- This is a Unity-based, client-only rhythm/game application that lets users create and play exercise routines to music (a “routine maker” rhythm game).
- Key indicators:
- Assets folder full of audio (MP3), JSON data for prologues and routines
- Scripts organized under Dialog, Play, Stage, UI, RoutineMaker
- Scenes like StartScene, MakeRoutine, Play, Stage, Prologues
- Plugins: FMOD (advanced audio middleware), SimpleFileBrowser, TextMesh Pro

##### File Structure Analysis
- Top-level folders:
- Assets – all game content (Audio, Sprites, Scenes, Prefabs, Scripts)
- Packages – manifest.json for Unity’s Package Manager
- ProjectSettings – engine configuration
- Under Assets:
- Plugins – third-party subsystems: FMOD (audio engine integration), SimpleFileBrowser (file I/O dialog), TextMesh Pro (text rendering)
- Scenes – each game state (start, prologue, routine maker, play, stage)
- Scripts – core game logic broken into subpackages:
– Dialog (text and dialogue control)
– Play (note spawning, verdict, results printing)
– Stage (player movement, environment interactions)
– UI (menus, settings, offset calibration)
– RoutineMaker (beat definition, save/load routines)
- PreRoutines – audio + JSON data for pre-built routines
- Configuration & build files: ProjectSettings, Packages/manifest.json

##### README Insights

1. Unity Engine Core
2. Scenes Manager
3. Game Logic Layer
- Dialog System
- Play System (NoteSpawner, NoteVerdict, Results)
- Stage System (Player controller, environment)
- RoutineMaker System (BeatInfo, SaveInfo)
4. UI Layer
- Settings & Offset Calibration
- Menus (Start, Pause/Esc, Next, BackToStage)
- File Browser (SimpleFileBrowser plugin)
5. Data Layer
- JSON Data (PreRoutines, Prologues, RoutineMaker save files)
- DataManager (load/save)
6. Audio Layer
- FMOD Plugin Runtime & Studio
- Unity AudioSource (fallback)
- Audio Assets (OffsetSFX, Prologue MP3)
7. External Subsystems
- FMOD Studio (audio middleware)
- SimpleFileBrowser (file dialog UI)
- TextMesh Pro (text rendering)

- Unity Engine ← loads → Scenes Manager
- Scenes Manager → instantiates → Game Logic & UI components
- Game Logic ↔ Data Layer (JSON load/save via DataManager)
- Game Logic → UI Layer (update scores, show dialogues)
- UI Layer → SimpleFileBrowser (open/save routines)
- Game Logic → FMOD Runtime (play event emitters, sound effects)
- FMOD Runtime → Audio Hardware (final sound output)
- InputSystem → UI & Game Logic (user taps, keypresses)

c. Architectural Patterns & Principles
- Component-based design (Unity GameObjects + MonoBehaviour scripts)
- MVC-like separation:
– Model: DataLayer (JSON, DataManager)
– View: UI Layer & Scenes
– Controller: Game Logic scripts
- Scene-driven flow: Start → Prologue → MakeRoutine → Play → Stage → Results

d. Key Technologies & Frameworks
- Unity Engine (2022+ with URP 2D)
- FMOD Unity Integration (audio events, banks)
- SimpleFileBrowser (runtime file dialogs for JSON)
- TextMesh Pro (advanced text UI)
- Unity Input System (InputSystem_Actions.asset)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Unity Core
    subgraph "Unity Core"
        Engine["Unity Engine Core"]:::unity
        ProjectSettings["ProjectSettings"]:::unity
        InputSystem["Input System"]:::unity
    end

    %% Scenes Manager
    subgraph "Scenes Manager"
        Scenes["Assets/Scenes"]:::unity
    end

    %% Game Logic Layer
    subgraph "Game Logic"
        Dialog["Dialog System"]:::logic
        NoteSpawn["NoteSpawn"]:::logic
        NoteVerdict["NoteVerdict"]:::logic
        PrintResult["PrintResult"]:::logic
        PlayerMoving["PlayerMoving"]:::logic
        StageDoor["StageDoor"]:::logic
        GymEquip["GymEquip"]:::logic
        BeatInfo["BeatInfo"]:::logic
        SaveInfo["SaveInfo"]:::logic
    end

    %% UI Layer
    subgraph "UI Layer"
        StartUI["StartUI"]:::ui
        SpinDisc["SpinDisc"]:::ui
        EnableMenu["EnableMenu"]:::ui
        SetOffset["SetOffset"]:::ui
        SettingUIPrefab["SettingUI.prefab"]:::ui
        OffsetSettingUIPrefab["OffsetSettingUI.prefab"]:::ui
    end

    %% Data Layer
    subgraph "Data Layer"
        DataManager["DataManager"]:::data
        PreRoutines["PreRoutines JSON"]:::data
        Prologues["Prologue JSON"]:::data
    end

    %% Audio Layer
    subgraph "Audio Layer"
        FMODRuntime["RuntimeManager"]:::audio
        OffsetSFX["OffsetSFX.mp3"]:::audio
        AudioHW["Audio Hardware"]:::audio
    end

    %% External Plugins
    subgraph "Plugins"
        SimpleFB["FileBrowser"]:::plugin
        FMODPlugin["FMOD Plugin"]:::plugin
        TMP["TextMesh Pro"]:::plugin
    end

    %% Connections
    Engine -->|loads| Scenes
    Scenes -->|instantiates| Dialog
    Scenes -->|instantiates| NoteSpawn
    Scenes -->|instantiates| PlayerMoving
    Scenes -->|instantiates| BeatInfo
    Scenes -->|instantiates| StartUI

    InputSystem -->|user input| StartUI
    InputSystem -->|user input| Dialog
    InputSystem -->|user input| NoteSpawn
    InputSystem -->|user input| PlayerMoving

    Dialog -->|ReadJSON/SaveJSON| DataManager
    NoteSpawn -->|ReadJSON| DataManager
    PrintResult -->|WriteJSON| DataManager
    BeatInfo -->|SaveRoutine| DataManager
    SaveInfo -->|LoadRoutine| DataManager

    DataManager -->|loads| PreRoutines
    DataManager -->|loads| Prologues

    StartUI -->|open dialog| SimpleFB
    SpinDisc -->|open file| SimpleFB
    EnableMenu -->|toggle| SettingUIPrefab
    SetOffset -->|adjust| OffsetSettingUIPrefab

    Dialog -->|play event| FMODRuntime
    NoteSpawn -->|play event| FMODRuntime
    FMODRuntime -->|output| AudioHW
    OffsetSFX -->|audio asset| FMODRuntime

    %% Click Events
    click Dialog "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/Dialog/DialogSystem.cs"
    click NoteSpawn "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/Play/NoteSpawn.cs"
    click NoteVerdict "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/Play/NoteVerdict.cs"
    click PrintResult "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/Play/PrintResult.cs"
    click PlayerMoving "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/Stage/PlayerMoving.cs"
    click StageDoor "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/Stage/StageDoor.cs"
    click GymEquip "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/Stage/GymEquip.cs"
    click BeatInfo "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/RoutineMaker/BeatInfo.cs"
    click SaveInfo "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/RoutineMaker/SaveInfo.cs"
    click StartUI "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/UI/StartUI.cs"
    click SpinDisc "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/UI/SpinDisc.cs"
    click EnableMenu "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/UI/Setting/EnableMenu.cs"
    click SetOffset "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/UI/Setting/SetOffset.cs"
    click SettingUIPrefab "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Prefab/SettingUI.prefab"
    click OffsetSettingUIPrefab "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Prefab/OffsetSettingUI.prefab"
    click SimpleFB "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs"
    click DataManager "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/Play/DataManager.cs"
    click PreRoutines "https://github.com/kh-returngame/rg2_rhythmhealth/tree/main/Assets/PreRoutines"
    click Prologues "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Scripts/Play/Prologue/*.json"
    click FMODRuntime "https://github.com/kh-returngame/rg2_rhythmhealth/blob/main/Assets/Plugins/FMOD/src/RuntimeManager.cs"

    %% Styles
    classDef unity fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef logic fill:#CCFFCC,stroke:#333,stroke-width:1px
    classDef ui fill:#FFE5CC,stroke:#333,stroke-width:1px
    classDef data fill:#F0F0F0,stroke:#333,stroke-width:1px
    classDef audio fill:#E6CCFF,stroke:#333,stroke-width:1px
    classDef plugin fill:#CCCCCC,stroke:#333,stroke-width:1px
```
