# hmazomba/greenhead architecture

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

- Interactive diagram: https://gitdiagram.com/hmazomba/greenhead
- Repository: https://github.com/hmazomba/greenhead

## Overview

##### Project Type and Purpose
- This is clearly a Unity project focused on creating a modular, data-driven state management/behavior system.
- It’s designed as a framework that handles FSM-style (finite state machine) logic for in-game characters or entities, including actions (e.g., camera control, movement), conditions (e.g., landing, vaulting), state transitions, and event handling.
- There is an integrated Behavior Editor (using custom Editor scripts) that likely allows designers to visually manage these states, transitions, and associated actions.

##### Analyzing the File Structure
- The “Palm Trees” folder (project root) contains an “Assets” folder, which is separated into subfolders for “Data” and “Scripts.”
- Under “Assets/Data” you find subdirectories like Actions, Conditions, Game Variables, Graphs, Inputs, Resources, State Actions, and States – all indicating that the project uses Scriptable Objects to store configuration and behavior data.
- Under “Assets/Scripts” you have the runtime code (StateManager, transitions, various behavior/action scripts) along with extensive support for the Behavior Editor (custom editor windows, nodes, custom inspectors) and utilities.
- The modular directory breakdown (e.g., “Behavior”, “Mono Actions”, “Conditions”, “State Actions”, “Scriptables”) suggests an emphasis on decoupling the data (via scriptable objects) from implementation details, following clear separation of concerns.

##### Key Components
a. Data Layer:
– Scriptable Objects for Actions, Conditions, State Actions, States, Inputs, Game Variables, and Vaulting data.
– Graph data (which likely represents the visual configuration of state transitions or behavior trees).
– Resource assets used by the editor and runtime (styles, skins, etc.).
b. Runtime Layer:
– Main behavior and state controller: The central “StateManager” that orchestrates behavior based on current state, inputs, and events.
– Animator and movement related scripts (like those handling camera control, jumping, vaulting, etc.).
– Mono Actions that react to engine events (e.g., DeltaTimeManager, InputManager).
c. Editor Layer:
– The Behavior Editor scripts and nodes (including custom inspectors and editor settings) that provide visual editing and debugging of behavior graphs.
– Editor-specific utilities for creating, managing, and updating state machine visualizations.
d. Interaction with Unity:
– Components such as “SimpleCameraController” showcase integration with Unity’s scene objects and camera system, while gameplay loop and updates are driven by common Unity MonoBehaviour patterns.

##### Relationships and Interactions
- The “StateManager” receives inputs (via Mono Actions/InputManager) and queries active conditions (from Conditions scripts/Scriptable data) to decide which state to transition into.
- Each state consists of associated “State Actions” and defined transitions which interlink with conditions.
- The Behavior Editor allows a designer to visually create and modify “Graphs” that tie the Scriptable Objects (states, transitions, conditions, etc.) together.
- Underlying game variables and conditions are continuously updated and used to determine runtime behavior.
- Data flow moves from inputs and events (user input, game events) → processed by the StateManager → executing actions and updating animations (linked with AnimatorData) → visualized and adjusted via the Behavior Editor tools.

##### Architectural Patterns and Design Principles
- The project uses a data-driven design approach enabled by Scriptable Objects; this allows for modularity and flexibility.
- Core to its architecture is an FSM pattern integrated with a visual behavior graph editor.
- Separation of concerns is evident: independent modules handle the logic (runtime scripts), configuration (data assets), and tooling (Editor scripts).

##### Technical Details
- Connections to clarify dependency and data flow (e.g., “reads from”, “updates”, “configured by”).
- High-level frameworks and libraries (Unity, Scriptable Objects) used in the design.

- A Data/Configuration layer (Scriptable Assets for states, transitions, conditions, etc.),
- A Runtime layer (the StateManager and associated MonoBehaviour scripts handling inputs, actions, and game logic),
- An Editor layer (custom tools for behavior graph editing).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data/Configuration Layer
    subgraph "Data/Configuration Layer"
        DS["Scriptable Assets"]:::data
    end

    %% Runtime Layer
    subgraph "Runtime Layer"
        SM["StateManager"]:::runtime
        MA["Mono Actions"]:::runtime
        SC["SimpleCameraController"]:::runtime
    end

    %% Editor Layer
    subgraph "Editor Layer"
        BE["Behavior Editor"]:::editor
        CI["Custom Inspectors"]:::editor
    end

    %% Connections
    MA -->|"inputs"| SM
    DS -->|"configures"| SM
    SM -->|"updates"| SC
    SM -->|"feedback"| BE
    CI -->|"edits"| SM
    BE -->|"configures"| DS

    %% Click Events
    click DS "https://github.com/hmazomba/greenhead/tree/master/Palm Trees/Assets/Data"
    click SM "https://github.com/hmazomba/greenhead/blob/master/Palm Trees/Assets/Scripts/StateManager.cs"
    click MA "https://github.com/hmazomba/greenhead/tree/master/Palm Trees/Assets/Scripts/Mono Actions"
    click SC "https://github.com/hmazomba/greenhead/blob/master/Palm Trees/Assets/Scripts/SimpleCameraController.cs"
    click BE "https://github.com/hmazomba/greenhead/tree/master/Palm Trees/Assets/Scripts/Editor/BehaviorEditor"
    click CI "https://github.com/hmazomba/greenhead/tree/master/Palm Trees/Assets/Scripts/Editor/Custom Inspectors"

    %% Styles
    classDef data fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef runtime fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef editor fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
