# airconsole/airconsole-unity-plugin architecture

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

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

## Overview

##### Main Components
- Unity Integration Core: Represent the Unity Editor/Runtime environment which consumes the plugin.
- AirConsole Plugin Module: This includes the C# wrapper (found in Assets/AirConsole/scripts and related editor scripts) that bridges Unity with the AirConsole JavaScript API.
- Embedded Webserver / WebSocket Server: A core part of the plugin responsible for enabling real-time communication between the AirConsole backend and the Unity Editor.
- Platform-Specific Resources and Templates:
– WebGLTemplates folder: Contains HTML/JS templates (for both older and newer versions, as seen in AirConsole-2020, AirConsole-U6) that form the front-end for the game’s controller interface.
– Android-related configurations: Found in Assets/Plugins/Android, which ensure proper integration with AndroidTV.
- Examples and Documentation:
– The examples in Assets/AirConsole/examples illustrate usage examples (basic, game states, platformer, pong, etc.), which inform the main flow and use cases.
– Documentation files (PDFs and README.txt) provide further guidance on how these components interact.
- Packaging and Build Tools:
– Assets/Packager shows build scripts used to create distributable Unity packages.
– GitHub Workflow files (in .github/workflows) for continuous integration/release activities.

##### Relationships & Interactions
– For WebGL, indicate that the module uses HTML/JS templates (i.e., controller templates from the WebGLTemplates folder).
– For AndroidTV, show that corresponding native configurations from Assets/Plugins/Android are involved.
- That the examples and documentation support developers in integrating and testing these components.
- Optionally, include a “Build & Deployment” subsystem where the Packager and GitHub workflows ensure a continuous and smooth release process.

##### Architectural Patterns or Design Principles
- Separation of concerns: the plugin abstracts the complexities of the AirConsole JavaScript API from the Unity game logic.
- Client–server communication model (even though it’s embedded), where the Unity plugin acts as a client interacting with a server-like component (the embedded webserver/websocket server).
- How platform-specific assets are separated (e.g., WebGL templates vs. Android plugins), following the “platform abstraction” principle.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Unity Integration Core
    subgraph "Unity Game / Editor"
        u1("Project Settings"):::unity
        u2("Unity Examples"):::unity
    end

    %% AirConsole Plugin Module (C# Wrapper)
    subgraph "AirConsole Plugin Module (C# Wrapper)"
        p1("C# Core Scripts"):::plugin
        p2("Editor Extensions"):::plugin
    end

    %% Embedded Webserver / WebSocket Server
    subgraph "Embedded Webserver / WebSocket Server"
        ws1("Websocket Listener"):::communication
        ws2("Editor Web Listener"):::communication
    end

    %% Platform-Specific Interfaces
    subgraph "Platform-Specific Interfaces"
        pl1("WebGL Templates"):::platform
        pl2("Android Integration"):::platform
    end

    %% External AirConsole API
    ex("External AirConsole API"):::external

    %% Examples & Documentation
    subgraph "Examples & Documentation"
        doc("Documentation"):::documentation
    end

    %% Packaging & Build Tools
    subgraph "Packaging & Build Tools"
        build1("Packager Scripts"):::build
        build2("CI/CD Workflows"):::build
    end

    %% Relationships
    u2 --> p1
    p1 --> ws1
    p2 --> ws2
    ws1 --> ex
    p1 --> pl1
    p1 --> pl2
    u2 -.-> doc
    p1 --> build1
    p2 --> build2

    %% Styles
    classDef unity fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef plugin fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef communication fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef platform fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef documentation fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef build fill:#E6E6FA,stroke:#000,stroke-width:2px;

    %% Click Events
    click u1 "https://github.com/airconsole/airconsole-unity-plugin/tree/master/ProjectSettings"
    click u2 "https://github.com/airconsole/airconsole-unity-plugin/tree/master/Assets/AirConsole/examples"
    click p1 "https://github.com/airconsole/airconsole-unity-plugin/tree/master/Assets/AirConsole/scripts"
    click p2 "https://github.com/airconsole/airconsole-unity-plugin/tree/master/Assets/AirConsole/scripts/editor"
    click ws1 "https://github.com/airconsole/airconsole-unity-plugin/blob/master/Assets/AirConsole/scripts/WebsocketListener.cs"
    click ws2 "https://github.com/airconsole/airconsole-unity-plugin/blob/master/Assets/AirConsole/scripts/editor/WebListener.cs"
    click pl1 "https://github.com/airconsole/airconsole-unity-plugin/tree/master/Assets/WebGLTemplates"
    click pl2 "https://github.com/airconsole/airconsole-unity-plugin/tree/master/Assets/Plugins/Android"
    click doc "https://github.com/airconsole/airconsole-unity-plugin/blob/master/Assets/AirConsole/README.txt"
    click build1 "https://github.com/airconsole/airconsole-unity-plugin/tree/master/Assets/Packager"
    click build2 "https://github.com/airconsole/airconsole-unity-plugin/tree/master/.github/workflows"
```
