# richrookie/unityframework architecture

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

- Interactive diagram: https://gitdiagram.com/richrookie/unityframework
- Repository: https://github.com/richrookie/unityframework

## Overview

##### Main Components
- Unity Core Integration – This represents the Unity engine’s lifecycle, interfacing with the game’s scenes and assets.
- Managers – Centralized components grouped under Assets/01Scripts/Manager:
- GameManager, DataManager, InputController/Manager, PoolManager (and Poolable), ResourceManager, SoundManager, and UIManager.
- Managers.cs which serves as a central access point for all manager components.
- UI Components – Including Assets/01Scripts/UI and prefabs from Assets/02Prefabs/UI. Emphasize UI_Base and its functions (binding components, event handling).
- Utility & Core Scripts – Located in Assets/01Scripts/Core and Assets/01Scripts/Util, containing common utility functions (like GetOrAddComponent, event binding, extension methods, etc.) and definitions.
- Scene and Level Management – Managed by Assets/01Scripts/Scenes (BaseScene, GameScene, SceneManagerEx) and the various scene collections in Assets/00Scenes.
- Editor Tools – Components in Assets/01Scripts/Editor that facilitate custom inspectors and auto-building, which aid developer productivity during design-time.
- Assets and Resources – Represented by directories like 02Prefabs, 03Materials, 04Textures, 05Animations, and 06Sounds. These are loaded via ResourceManager and are the building blocks for game visuals and sounds.

##### Relationships and Data Flow
- The Unity Engine acts as the runtime environment, initiating Scenes from the 00Scenes folder.
- On scene load, the Managers initialize (using Managers.cs) and manage various aspects:
- Input controllers pick up user inputs.
- PoolManager handles object pooling for performance (triggered by Poolable components).
- ResourceManager handles instantiation and destruction of prefabs and material resources.
- UIManager orchestrates UI elements created from UI_Base scripts, with data and events coming from GameManager/DataManager.
- SoundManager remotely controls audio feedback.
- Utility classes (Util, Define, and Extension methods) support the core functionality across systems.
- Editor scripts provide design-time tools, ensuring that the architecture remains consistent and effects such as auto-building or custom property inspections are efficient.

##### Architectural Patterns and Design Principles
- Component-based Architecture: Unity’s MonoBehaviour design is at the core. Each Manager and UI component is built as a MonoBehaviour that can be attached to GameObjects.
- Centralized Management: The use of a singular Managers.cs that acts as a gateway to all other managers exemplifies the Service Locator pattern.
- Reusability and Extensibility: Utility functions and extensions are designed to simplify common tasks, reducing redundancy.
- Separation of Concerns: The folder structure (Scenes, Scripts, Prefabs, etc.) clearly separates visual assets from logic and editor tools, maintaining modularity.

##### Relevant Technologies and Frameworks
- Unity Engine: The base platform where everything runs.
- Unity Editor Extensions: Custom editors found in the Assets/01Scripts/Editor folder indicate enhancements to the Unity Inspector for managing UI and build processes.
- C# Scripting: The project is implemented in C# which uses object-oriented patterns and extension methods heavily.
- ResourceLoader Pattern: The ResourceManager implements the Resources.Load/Instantiate methods common in Unity for asset management.

##### Elements
- Runtime components (e.g., Managers, UI, Scenes).
- Support utilities (e.g., Util, Define, Extension).
- Editor/Development tools (e.g., AutoBuilder, Custom Editors).

- Branch out to show the initialization of Managers (GameManager, DataManager, etc.). Indicate that these components are accessible via a central Managers.cs.
- From the Managers, branch out to:
- Input handling, using InputController and InputManager.
- Resource management, pointing to ResourceManager which accesses Asset folders (02Prefabs, 03Materials, etc.).
- Sound and UI management linking to the prefabs in Assets.
- Scene management sub-system (SceneManagerEx, BaseScene, GameScene) as a separate node that interacts with Managers.
- Optionally, include a side node for the Editor tools to show how developers can manage the auto-building process and custom inspectors through the Editor folder.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level Unity Environment
    UnityEngine["Unity Engine"]:::unity
    UnityScenes["Scenes (Assets/00Scenes)"]:::scenes
    UnityEngine -->|"SceneLoad"| UnityScenes
    %% Scene Management initiates Managers via scene load
    UnityScenes -->|"InitManagers"| ManagersAccess["Central Manager Access (Managers.cs)"]:::managers

    %% Subgraph: Managers
    subgraph "Managers"
        GameManager["GameManager"]:::managers
        DataManager["DataManager"]:::managers
        InputController["InputController"]:::managers
        InputManager["InputManager"]:::managers
        PoolManager["PoolManager"]:::managers
        Poolable["Poolable"]:::managers
        ResourceManager["ResourceManager"]:::managers
        SoundManager["SoundManager"]:::managers
        UIManager["UIManager"]:::managers
    end

    %% Connections from Central Manager Access to individual managers
    ManagersAccess -->|"accesses"| GameManager
    ManagersAccess --> DataManager
    ManagersAccess --> InputController
    ManagersAccess --> InputManager
    ManagersAccess --> PoolManager
    ManagersAccess --> Poolable
    ManagersAccess --> ResourceManager
    ManagersAccess --> SoundManager
    ManagersAccess --> UIManager

    %% Additional Manager interactions
    InputController -->|"input"| GameManager
    DataManager -->|"datasync"| UIManager

    %% Subgraph: UI Components
    subgraph "UI Components"
        UI_Base["UI_Base"]:::ui
        UI_EventHandler["UI_EventHandler"]:::ui
        UI_GameScene["UI_GameScene"]:::ui
        UI_Popup["UI_Popup"]:::ui
        UI_Scene["UI_Scene"]:::ui
        UI_Prefabs["UI Prefabs"]:::assets
    end
    %% UI Manager creates and manages UI Components
    UIManager -->|"manages"| UI_Base

    %% Subgraph: Utility & Core Scripts
    subgraph "Utility & Core Scripts"
        CoreUtilities["Core Utilities"]:::util
        UtilityFunctions["Utility Functions & Definitions"]:::util
    end
    %% Utilities support Managers and UI Components
    UtilityFunctions -->|"supports"| GameManager
    UtilityFunctions --> UI_Base

    %% Subgraph: Scene and Level Management
    subgraph "Scene Management"
        BaseScene["BaseScene"]:::scenes
        GameScene["GameScene"]:::scenes
        SceneManagerEx["SceneManagerEx"]:::scenes
    end
    %% Scene management interacts with the core flow
    UnityScenes -->|"managesScenes"| SceneManagerEx
    SceneManagerEx -->|"triggersTransition"| ManagersAccess

    %% Subgraph: Editor Tools
    subgraph "Editor Tools"
        EditorScripts["Editor Scripts"]:::editor
    end

    %% Subgraph: Assets & Resources
    subgraph "Assets & Resources"
        Prefabs["Prefabs & GameObjects"]:::assets
        Materials["Materials"]:::assets
        Textures["Textures"]:::assets
        Animations["Animations"]:::assets
        Sounds["Sounds"]:::assets
    end
    %% ResourceManager loads assets from Resources
    ResourceManager -->|"loads"| Prefabs
    ResourceManager --> Materials
    ResourceManager --> Textures
    ResourceManager --> Animations
    ResourceManager --> Sounds

    %% Click Event Bindings
    click UnityScenes "https://github.com/richrookie/unityframework/tree/Main/Assets/00Scenes"
    click ManagersAccess "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Manager/Managers.cs"
    click GameManager "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Manager/GameManager.cs"
    click DataManager "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Manager/DataManager.cs"
    click InputController "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Manager/InputController.cs"
    click InputManager "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Manager/InputManager.cs"
    click PoolManager "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Manager/PoolManager.cs"
    click Poolable "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Manager/Poolable.cs"
    click ResourceManager "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Manager/ResourceManager.cs"
    click SoundManager "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Manager/SoundManager.cs"
    click UIManager "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Manager/UIManager.cs"
    click UI_Base "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/UI/UI_Base.cs"
    click UI_EventHandler "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/UI/UI_EventHandler.cs"
    click UI_GameScene "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/UI/UI_GameScene.cs"
    click UI_Popup "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/UI/UI_Popup.cs"
    click UI_Scene "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/UI/UI_Scene.cs"
    click UI_Prefabs "https://github.com/richrookie/unityframework/blob/Main/Assets/02Prefabs/UI/Resources/UI_GameScene.prefab"
    click CoreUtilities "https://github.com/richrookie/unityframework/tree/Main/Assets/01Scripts/Core"
    click UtilityFunctions "https://github.com/richrookie/unityframework/tree/Main/Assets/01Scripts/Util"
    click BaseScene "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Scenes/BaseScene.cs"
    click GameScene "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Scenes/GameScene.cs"
    click SceneManagerEx "https://github.com/richrookie/unityframework/blob/Main/Assets/01Scripts/Scenes/SceneManagerEx.cs"
    click EditorScripts "https://github.com/richrookie/unityframework/tree/Main/Assets/01Scripts/Editor"
    click Prefabs "https://github.com/richrookie/unityframework/tree/Main/Assets/02Prefabs"
    click Materials "https://github.com/richrookie/unityframework/tree/Main/Assets/03Materials"
    click Textures "https://github.com/richrookie/unityframework/tree/Main/Assets/04Textures"
    click Animations "https://github.com/richrookie/unityframework/tree/Main/Assets/05Animations"
    click Sounds "https://github.com/richrookie/unityframework/tree/Main/Assets/06Sounds"

    %% Styles
    classDef unity fill:#cce5ff, stroke:#004085, stroke-width:2px;
    classDef managers fill:#d4edda, stroke:#155724, stroke-width:2px;
    classDef ui fill:#fff3cd, stroke:#856404, stroke-width:2px;
    classDef util fill:#e2e3e5, stroke:#6c757d, stroke-width:2px;
    classDef scenes fill:#f8d7da, stroke:#721c24, stroke-width:2px;
    classDef editor fill:#d1ecf1, stroke:#0c5460, stroke-width:2px;
    classDef assets fill:#fefefe, stroke:#818182, stroke-width:2px;
```
