# levi0309/unity- architecture

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

- Interactive diagram: https://gitdiagram.com/levi0309/unity-
- Repository: https://github.com/levi0309/unity-

## Overview

The project is a Unity-based, turn-based, card-driven roguelike game (类杀戮尖塔回合制卡牌肉鸽游戏) similar in design to “Slay the Spire.” The file tree highly emphasizes Unity’s folder structure with extensive organization of assets, scenes, scripts, and external libraries (for example, DOTween, Spine, and TextMesh Pro). There is also a clear emphasis on card data, character logic, turn-based management, UI, and event handling.

##### Main Components
- Game Managers: Central control modules are visible under Assets/Scripts/Manager. These include modules like GameManager, CardManager, SceneLoadManager, TurnBaseManager, UIManager, and CardLayoutManager. They orchestrate the game flow, transitions, and core logic.
- Card System: Organize components like CardDataSO, CardLibrarySO, Card logic (in Assets/Scripts/Card/Logic), and card effects (Assets/Scripts/CardEffect). This represents the core deck-building mechanics.
- Characters and Enemies: The folders under Assets/Scripts/Character (Player.cs, Enemy.cs, BOSS.cs) show dedicated logic for various characters with animations, event-based interactions, and controllers.
- Room/Map and Turn Modules: Assets/Scripts/Room and Assets/GameData/RoomData define the “dungeon” or map generation aspects, which together with turn-based logic (Assets/Scripts/Manager/TurnBaseManager) control the game’s progression.
- Event System: A clearly modular event system is present in Assets/Scripts/Event with Data_SO, Listener classes, and editors. This system manages game events (like character death or new room loading) using the observer pattern.
- UI and Visual Effects: The UI components (under Assets/UI and Assets/Scripts/UI) and the VFX modules (Assets/Scripts/VFX) control the game interface and animations. Also note integration with TextMesh Pro and Unity’s UI Toolkit.
- External Tools and Middleware: Integration of external libraries such as DOTween (in Assets/Plugins/Demigiant/DOTween) for tweening animations and Spine (under Assets/Spine) for skeletal animation is critical to the project’s visual presentation.

##### Relationships and Interactions
- The GameManager sits at the heart of the architecture, coordinating gameplay by invoking calls to the CardManager (for drawing and managing cards) and TurnBaseManager (for controlling game phases).
- SceneLoadManager transitions between different game scenes (Menu, Map, Combat, etc.), while UIManager renders panels like game menus, gameplay HUD, and results screens.
- The Card System interacts with both the player’s strategic choices and the event system. Card effects (such as DamageEffect or HealEffect) trigger events that are captured by the Event System to update character states.
- The Room/Map logic manages level generation (using MapGenerator and Room logic) and ties into the turn-based cycle to set up combat and exploration scenarios.
- The Event System is integrated throughout – managers, UI components, and game logic all communicate type-safe events ensuring synchronized state changes.

##### Architectural Patterns
- MVC / Component-based Design: The separation between visual assets (UI/Art/Scenes), game logic (Scripts/), and configuration (GameData, ScriptableObjects) is clear. This separation is influenced by Unity’s component-based design.
- Observer Pattern: The event system uses this pattern to decouple event producers and consumers.
- ScriptableObject Pattern: Extensive use of SO files in data (e.g., CardDataSO, RoomData_SO, various Event SOs) encapsulates configuration and shared assets.
- Manager / Director Pattern: Managers orchestrate overall game flow across different aspects (UI, scenes, turns, deck-handling).

##### Including Relevant Technologies, Frameworks, and Libraries
- Unity Engine: Core engine with its scene management and component system.
- DOTween: For tweening and smooth animations.
- Spine: For advanced skeletal animations (used in character and enemy animations).
- TextMesh Pro and UI Toolkit: For rendering modern UI elements.
- Various Unity packages (e.g., Addressables, Shader Graph) used for asset tracking and rendering.

- Use Clear Labels: Each node should be titled exactly as the component (for example, GameManager, CardManager, TurnBaseManager, etc.).
– GameManager → CardManager, TurnBaseManager, SceneLoadManager
– CardManager → Event System (when a card is played, triggers relevant events)
– Event System → UIManager and Character modules (for state updates)
– UI interactions → GameManager (to signal player input)
– Scene transitions from SceneLoadManager → Various Scenes
– For instance, blue blocks for Managers; green blocks for data/models (ScriptableObject based configuration); orange blocks for UI components; and yellow blocks for external tool integrations.
- Notes: Annotate special patterns (e.g., “Observer Pattern for Event Handling” and “ScriptableObject based configuration”) where needed.

- Surround it with distinct modules for Card System, Character/Enemy System, Room/Map Generation, UI/VFX, and the Event System.
- Supporting layers for configuration and external tools.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Game Managers
    subgraph "Game Managers"
        GM["GameManager"]:::manager
        CM["CardManager"]:::manager
        SLM["SceneLoadManager"]:::manager
        TBM["TurnBaseManager"]:::manager
        UM["UIManager"]:::manager
        CLM["CardLayoutManager"]:::manager
    end

    %% Card System
    subgraph "Card System"
        CDSO["CardDataSO"]:::data
        CLSO["CardLibrarySO"]:::data
        CL["Card Logic"]:::card
        CE["Card Effects"]:::card
    end

    %% Characters and Enemies
    subgraph "Characters and Enemies"
        P["Player"]:::character
        E["Enemy"]:::character
        B["Boss"]:::character
    end

    %% Room and Map Generation
    subgraph "Room/Map Generation"
        MG["Map Generator"]:::manager
        RM["Room Module"]:::manager
        RD["Room Data"]:::data
    end

    %% Event System
    subgraph "Event System"
        ES["Event System"]:::event
    end

    %% UI and VFX
    subgraph "UI and VFX"
        UI["UI Components"]:::ui
        VFX["VFX Controller"]:::vfx
    end

    %% External Tools
    subgraph "External Tools"
        DT["DOTween"]:::external
        SP["Spine"]:::external
        TMP["TextMesh Pro"]:::external
    end

    %% Relationships
    GM -->|"controls"| CM
    GM -->|"controls"| TBM
    GM -->|"controls"| SLM
    GM -->|"controls"| UM
    GM -->|"controls"| CLM

    CM -->|"triggersEvent"| ES
    CE -->|"triggersEvent"| ES

    ES -->|"updateUI"| UI
    ES -->|"updateState"| P
    ES -->|"updateState"| E
    ES -->|"updateState"| B

    UI -->|"playerInput"| GM

    MG -->|"generatesRooms"| RM
    RD -->|"configures"| RM
    RM -->|"setsTurnCycle"| TBM

    DT -->|"tweening"| VFX
    SP -->|"animates"| P
    SP -->|"animates"| E
    SP -->|"animates"| B
    TMP -->|"renders"| UI

    %% Styles
    classDef manager fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef data fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef card fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef character fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef event fill:#D8BFD8,stroke:#000,stroke-width:2px;
    classDef ui fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef vfx fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef external fill:#FFFF99,stroke:#000,stroke-width:2px;

    %% Click Events
    click GM "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Manager/GameManager.cs"
    click CM "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Manager/CardManager.cs"
    click SLM "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Manager/SceneLoadManager.cs"
    click TBM "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Manager/TurnBaseManager.cs"
    click UM "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Manager/UIManager.cs"
    click CLM "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Manager/CardLayoutManager.cs"

    click CDSO "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Card/Data/CardDataSO.cs"
    click CLSO "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Card/Data/CardLibrarySO.cs"
    click CL "https://github.com/levi0309/unity-/tree/main/Assets/Scripts/Card/Logic/"
    click CE "https://github.com/levi0309/unity-/tree/main/Assets/Scripts/CardEffect/"

    click P "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Character/Player.cs"
    click E "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Character/Enemy.cs"
    click B "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Character/BOSS.cs"

    click MG "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Room/Logic/MapGenerator.cs"
    click RM "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/Room/Logic/Room.cs"
    click RD "https://github.com/levi0309/unity-/tree/main/Assets/GameData/RoomData/"

    click ES "https://github.com/levi0309/unity-/tree/main/Assets/Scripts/Event/"

    click UI "https://github.com/levi0309/unity-/tree/main/Assets/Scripts/UI/"
    click VFX "https://github.com/levi0309/unity-/blob/main/Assets/Scripts/VFX/VFXController.cs"

    click DT "https://github.com/levi0309/unity-/tree/main/Assets/Plugins/Demigiant/DOTween"
    click SP "https://github.com/levi0309/unity-/tree/main/Assets/Spine"
    click TMP "https://github.com/levi0309/unity-/tree/main/Assets/TextMesh Pro"
```
