# phungbatung/timetwin architecture

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

- Interactive diagram: https://gitdiagram.com/phungbatung/timetwin
- Repository: https://github.com/phungbatung/timetwin

## Overview

##### Main Components
- Game Engine Core: Represent Unity’s built-in systems (e.g., Scene Management, Physics2D, Renderer, Input Manager). Although these are implicit, they provide the runtime environment.
- Assets/Content: Include subcomponents like:
– Animation: Controls animations (using animation clips, controllers, etc.)
– Data: Level data and configuration items (LevelsData).
– Materials, Sprites, and TextMesh Pro resources for rendering and UI.
- Plugins: Highlight DOTween, which enables advanced tweening for game object animations and transitions. Note the structure under Assets/Plugins/Demigiant/DOTween.
- Scripts: The heart of the game logic is implemented in the various scripts:
– Controller: Includes Avatar, PlayerMovement, CloneMovement, and MoveablePlatform classes. These drive character and object behaviors.
– GameplayElements: Contains key game mechanics (ActivatedDoor, PortalSystem, BoxShape, etc.), which manage interactions like doors, portals, and other environment triggers.
– Game Manager: Central game flow (GameManager.cs) orchestrates states, level transitions, and overall game logic.
– LevelData: Scripts managing level configurations and level-related state.
– Record: Contains ReplaySystem and RecordData along with UI timer management for recording or gameplay replay features.
– UI: Organized under Scripts/UI, handling buttons (e.g., Menu, Next, Quit, Record) and Level Selection to create interactive game menus.
- Scenes: Contains several Unity scene files that lay out the game’s levels, menus, and templates (e.g., LevelMenu, StartScene, LevelSceneTemplate). These represent entry points into the game.
- Input System: Managed under Assets/InputSystem with configurations for different types of input actions (e.g., ControllerInput, PlayerInput).

##### Relationships and Interactions
- The Game Manager sits central in the architecture and coordinates scene transitions, level loading, and state management.
- Controllers (Avatar, PlayerMovement, etc.) interact directly with the Game Manager and possibly with UI elements or game physics.
- The GameplayElements (e.g., PortalSystem, ActivatedDoorSystem) interact with both the Game Manager and individual controllers to drive level interactions.
- LevelData and Data assets provide configuration and runtime values that are consumed by the Game Manager and various Scripts controlling gameplay.
- The UI system interacts with the Game Manager (to trigger level changes, record gameplay, pause/resume, etc.) and uses event-based inputs.
- DOTween (from the Plugins folder) is leveraged in various scripts to perform animations and transitions.

##### Architectural Patterns and Design Principles
- Modular Design: The scripts are divided into logical modules: Controllers, GameplayElements, UI, and Record. This modularization ensures each component is individually manageable and testable.
- Event-driven Interactions: Likely used in input handling and UI button events to trigger game logic (e.g., level selection, game state transitions).
- Use of External Plugins: DOTween is a notable external dependency that abstracts animation interpolation, highlighting a reliance on third-party time-based transitions.

##### Relevant Technologies and Frameworks
- Unity Engine – for rendering, physics, scene management, and overall game runtime.
- DOTween Framework – for tween-based animations and smooth transitions.
- Unity Input System – a modern approach for handling various input devices.
- Unity UI (likely powered by TextMesh Pro for text rendering as seen in the project).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Game Logic"
        GM["Game Manager"]:::logic
        CS["Controller Scripts"]:::logic
        GE["Gameplay Elements"]:::logic
        RM["Record Module"]:::logic
        UI["UI System"]:::ui
        LD_S["LevelData Scripts"]:::data
        IS["Input System"]:::input
    end

    subgraph "Game Content"
        LD["Levels Data Asset"]:::data
        ANIM["Animation"]:::anim
        MAT["Materials"]:::visual
        SPR["Sprites"]:::visual
        TMP["TextMesh Pro"]:::visual
        SC["Scenes"]:::scenes
        SCRES["Resource Scenes"]:::scenes
    end

    UE["Unity Engine Core"]:::core
    DS["DOTween Plugin"]:::plugin

    %% Relationships
    UE --> GM
    GM --> CS
    GM --> GE
    GM --> RM
    GM --> UI
    GM --> LD_S
    GM --> LD
    GM --> SC
    GM --> SCRES

    IS --> CS
    IS --> GM

    UI -->|"triggers"| GM

    DS --> ANIM
    DS --> UI

    ANIM --> MAT
    ANIM --> SPR
    ANIM --> TMP

    CS --> GE

    %% Click Events
    click GM "https://github.com/phungbatung/timetwin/blob/main/Assets/Scripts/GameManager.cs"
    click CS "https://github.com/phungbatung/timetwin/tree/main/Assets/Scripts/Controller"
    click GE "https://github.com/phungbatung/timetwin/tree/main/Assets/Scripts/GameplayElements"
    click RM "https://github.com/phungbatung/timetwin/tree/main/Assets/Scripts/Record"
    click UI "https://github.com/phungbatung/timetwin/tree/main/Assets/Scripts/UI"
    click LD_S "https://github.com/phungbatung/timetwin/tree/main/Assets/Scripts/LevelData"
    click IS "https://github.com/phungbatung/timetwin/tree/main/Assets/InputSystem"
    click LD "https://github.com/phungbatung/timetwin/tree/main/Assets/Data"
    click ANIM "https://github.com/phungbatung/timetwin/tree/main/Assets/Animation"
    click MAT "https://github.com/phungbatung/timetwin/tree/main/Assets/Material"
    click SPR "https://github.com/phungbatung/timetwin/tree/main/Assets/Sprites"
    click TMP "https://github.com/phungbatung/timetwin/tree/main/Assets/TextMesh Pro"
    click SC "https://github.com/phungbatung/timetwin/tree/main/Assets/Scenes"
    click SCRES "https://github.com/phungbatung/timetwin/tree/main/Assets/Resources/LevelScene"
    click DS "https://github.com/phungbatung/timetwin/tree/main/Assets/Plugins/Demigiant/DOTween"

    %% Styles
    classDef core fill:#ffcc00,stroke:#000,stroke-width:2px;
    classDef logic fill:#cce5ff,stroke:#000,stroke-width:2px;
    classDef data fill:#ffffcc,stroke:#000,stroke-width:2px;
    classDef anim fill:#d1c4e9,stroke:#000,stroke-width:2px;
    classDef visual fill:#f8bbd0,stroke:#000,stroke-width:2px;
    classDef ui fill:#ffcccb,stroke:#000,stroke-width:2px;
    classDef plugin fill:#c8e6c9,stroke:#000,stroke-width:2px;
    classDef scenes fill:#b3e5fc,stroke:#000,stroke-width:2px;
    classDef input fill:#e1bee7,stroke:#000,stroke-width:2px;
```
